Skip to content

Instantly share code, notes, and snippets.

@T3aHat
Last active January 9, 2024 23:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save T3aHat/41b6f42f4cd01d88127971596d262fe7 to your computer and use it in GitHub Desktop.
Save T3aHat/41b6f42f4cd01d88127971596d262fe7 to your computer and use it in GitHub Desktop.
ExcelでDeepL翻訳
Attribute VB_Name = "ExcelDeepL"
' # Installation
' 1. Activate MicroSoft XML. v6.0 and MicroSoft Scripting Runtime
' 2. Get VBA-JSON(JsonConverter.bas) from https://github.com/VBA-tools/VBA-JSON
' 3. Install JsonConverter and this script
' # How to use
' deepl(target_lang, select a cell)
' Example: deepl("JA",A1)
' # target_lang
' "BG" - Bulgarian
' "CS" - Czech
' "DA" - Danish
' "DE" - German
' "EL" - Greek
' "EN" - English
' "ES" - Spanish
' "ET" - Estonian
' "FI" - Finnish
' "FR" - French
' "HU" - Hungarian
' "IT" - Italian
' "JA" - Japanese
' "LT" - Lithuanian
' "LV" - Latvian
' "NL" - Dutch
' "PL" - Polish
' "PT" - Portuguese (all Portuguese varieties mixed)
' "RO" - Romanian
' "RU" - Russian
' "SK" - Slovak
' "SL" - Slovenian
' "SV" - Swedish
' "ZH" - Chinese
Option Explicit
Function deepl(lang As String, text As String) As String
Dim api_key As String
api_key = "Input_your_DeepL_APIKEY(FREE)"
Dim url As String
url = "https://api-free.deepl.com/v2/translate"
Dim paramStr As String
paramStr = "auth_key=" + api_key + "&target_lang=" + lang + "&text=" + text
Dim r As Object
Set r = CreateObject("msxml2.xmlhttp")
r.Open "POST", url, False
r.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; utf-8"
r.send (paramStr)
Dim json As Object
Set json = JsonConverter.ParseJson(r.responseText)
deepl = json("translations")(1)("text")
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment