คือผมมี VBA Code ที่ใช้ Excel เป็นตัวส่งข้อความหรือรูป เข้า Line message แต่ผมติดปัญหาที่ผมต้องส่งข้อความไปพร้อมกับการแนบรูป ผมไม่อยากส่งข้อความไปด้วยครับ อยากส่งแค่รูปต้องปรับแก้ตรงไหนครับ
Sub Line01()
Dim URL As String
Dim sToken As String
Dim sFilepath As String
Dim nFile As Integer
Dim baBuffer() As Byte
Dim ssPostData1 As String
Dim ssPostData2 As String
Dim ssPostData3 As String
Dim Messagelength As Integer
Dim arr1() As Byte
Dim arr2() As Byte
Dim arr3() As Byte
Dim arr4() As Byte
Const STR_BOUNDARY As String = "------------------------058b4eeb7d99b4f6"
sToken = Sheets("Token").Range("B2") <<< Token
URL = "
https://notify-api.line.me/api/notify"
sFilepath = Sheets("Token").Range("A25") <<<<รูปที่ 1
sFileName = GetFilenameFromPath(sFilepath)
ssPostData1 = vbCrLf & _
"--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=" & """message""" & vbCrLf & vbCrLf
arr1 = StrConv(ssPostData1, vbFromUnicode)
arr2 = (" ")
<<<<< ข้อความผมปล่อยให้เป็นค่าว่าง
ssPostData2 = vbCrLf & _
"--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=" & """imageFile""" & "; filename=" & sFileName & vbCrLf & _
"Content-Type: image/jpng" & vbCrLf & vbCrLf
arr3 = StrConv(ssPostData2, vbFromUnicode)
nFile = FreeFile
Open sFilepath For Binary Access Read As nFile
If LOF(nFile) > 0 Then
ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
Get nFile, , baBuffer
imagear = baBuffer
End If
Close nFile
arr4 = StrConv(vbCrLf & "--" & STR_BOUNDARY & "--" & vbCrLf, vbFromUnicode)
Dim arraytotal As Long
Dim sendarray() As Byte
arraytotal = UBound(arr1) + UBound(arr2) + UBound(arr3) + UBound(imagear) + UBound(arr4) + 4
ReDim sendarray(arraytotal)
For i = 0 To UBound(arr1)
sendarray(i) = arr1(i)
Next
For i = 0 To UBound(arr2)
sendarray(UBound(arr1) + i + 1) = arr2(i)
Next
For i = 0 To UBound(arr3)
sendarray(UBound(arr1) + UBound(arr2) + i + 2) = arr3(i)
Next
For i = 0 To UBound(imagear)
sendarray(UBound(arr1) + UBound(arr2) + UBound(arr3) + i + 3) = imagear(i)
Next
For i = 0 To UBound(arr4)
sendarray(UBound(arr1) + UBound(arr2) + UBound(arr3) + UBound(imagear) + i + 4) = arr4(i)
Next
With CreateObject("Microsoft.XMLHTTP")
.Open "POST", URL, 0
.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & STR_BOUNDARY
.SetRequestHeader "Authorization", "Bearer " & sToken
.send sndar(sendarray)
Debug.Print .responseText
End With
End Sub
Public Function sndar(sendarray As Variant) As Byte()
sndar = sendarray
End Function
Public Function GetFilenameFromPath(ByVal strPath As String) As String
If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
End If
End Function
You do not have the required permissions to view the files attached to this post.