返回列表 上一主題 發帖

[發問] 使用excel vba上傳圖檔到line

[發問] 使用excel vba上傳圖檔到line

關於line notify應用, 請問要怎麼把圖檔送到line的群組裡面?
圖檔路徑是F:\test.png
我參考https://notify-bot.line.me/doc/en/ 官網的說明,
裡面有提到要用imagefile, 但仍不知如何下手
請各位前輩指教@@

附上原始碼
  1. Sub line_notify_圖片()   
  2.      '===================================
  3.     'Line訊息
  4.     '===================================
  5.     Dim oXML As Object
  6.    
  7.     Dim Token As String
  8.    
  9.     Dim URL As String
  10.    
  11.     '指定的Line Notify Token
  12.    
  13.     Token = "你的TOKEN"
  14.    
  15.     'Line Notify的傳送訊息網址
  16.        
  17.         Line_Message = "str test"
  18.    
  19.     URL = "https://notify-api.line.me/api/notify"

  20.     Set oXML = CreateObject("Microsoft.XMLHTTP")
  21.    
  22.     With oXML
  23.    
  24.         '使用同步傳輸
  25.    
  26.         .Open "POST", URL, 0
  27.    
  28.         '設定傳送封包Header
  29.    
  30.         .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  31.    
  32.         .SetRequestHeader "Authorization", "Bearer " & Token
  33.    
  34.         '執行Ajax傳送
  35.         .send "message=" & Chr(10) & Line_Message
  36.         Debug.Print oXML.responseText
  37.    
  38.     End With
  39.    
  40.     '釋放物件資源
  41.    
  42.     Set oXML = Nothing
  43. End Sub
複製代碼

資料來源https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11237902231
  1. Sub Sample()
  2. Dim msg As String: msg = "Hello"
  3. Dim imgPath As String: imgPath = "C:\Users\hoge\Desktop\test.jpg"
  4. Shell "curl.exe" & _
  5. " -X POST https://notify-api.line.me/api/notify" & _
  6. " -H ""Authorization: Bearer 5Cx15az4Ka1Gl3idjF5kxYmHg13Ja1xOWsRPkzMaLPh""" & _
  7. " -F message=" & msg & _
  8. " -F imageFile=@" & imgPath, vbNormalFocus

  9. End Sub
複製代碼

TOP

回復 2# yws0915


    問題是我想將msg="Hello"改成中文,msg="你好"就出現問題,可以幫我解決問題嗎?謝謝

Sub Sample()
Dim msg As String: msg = "你好"
Dim imgPath As String: imgPath = "C:\Users\hoge\Desktop\test.jpg"
Shell "curl.exe" & _
" -X POST https://notify-api.line.me/api/notify" & _
" -H ""Authorization: Bearer 5Cx15az4Ka1Gl3idjF5kxYmHg13Ja1xOWsRPkzMaLPh""" & _
" -F message=" & msg & _
" -F imageFile=@" & imgPath, vbNormalFocus

End Sub
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 3# 7777


    " -F message=" & msg & _

改成

" -F message=" & WorksheetFunction.EncodeURL(msg) & _

TOP

回復 4# singo1232001


    感謝

修改後 出現 圖1

你好.jpg
50 字節以內
不支持自定義 Discuz! 代碼

TOP

本帖最後由 singo1232001 於 2023-2-11 07:36 編輯

回復 5# 7777

http://white5168.blogspot.com/2017/01/line-notify-6-line-notify.html#.Y-bI8nZBxPY
我查了一下


我建議 分段傳
圖片用curl 這段 好像只支援 日 韓 英

傳完圖片
等五秒
再用正常的傳訊方式傳訊息

但圖片的部分 我還沒測試成功
看到要server才能傳 目前我的功力跟基礎不夠

不過 看他056 這行 確實可以用中文字傳送    arr2 = Utf8BytesFromString("小天使圖傳送!!!LaLaLa~~~")
最後也有顯示中文

再參考看看

TOP

回復 5# 7777


我用你的程式碼測中文字,正常輸出
win10



TOP

回復 7# quickfixer


    感謝解說~~

不懂!!
試了很多次,還是都不成功,
這跟電腦環境有差嗎??
win10 ,2019 版本office  64位元 (應該OK)
還是需要安裝什麼 ??
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 7# quickfixer


    測試的三台電腦皆不行,英文都OK
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 9# 7777

試了win7 office2016
Win10 office2019,都正常,只装curl
其它都是剛重灌好

測試用手機是android系統

TOP

        靜思自在 : 屋寬不如心寬。
返回列表 上一主題