snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub SendMessageToLineNotify()
Dim oXML As Object
Dim strToken As String
Dim strMessage As String
Dim strDate As String
Dim URL As String
strToken = Sheet1.Range("B1")
URL = "https://notify-api.line.me/api/notify"
strDate = Format(Now, "DD/MM/YYYY - HH:MM:SS")
Pic = "C:\All\1.jpg"
strMessage = "message=" & strDate & Pic
Set oXML = CreateObject("Microsoft.XMLHTTP")
With oXML
.Open "POST", URL, 0
.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.SetRequestHeader "Authorization", "Bearer " & strToken
.send (strMessage)
Debug.Print oXML.responseText
End With
Set oXML = Nothing
End Sub
You do not have the required permissions to view the files attached to this post.
Sub SendPictureViaLineNotify()
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
Dim arraytotal As Long
Dim sendarray() As Byte
Const STR_BOUNDARY As String = "------------------------058b4eeb7d99b4f6"
sToken = "Your token" 'Paste your token after equal sign
URL = "https://notify-api.line.me/api/notify"
sFilepath = Application.GetOpenFilename(FileFilter:="Picture (*.jpg*),*.jpg*,(*.png*),*.png*")
If sFilepath = "False" Then Exit Sub
sfilename = VBA.Right(sFilepath, VBA.InStr(VBA.StrReverse(sFilepath), "\") - 1)
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)
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)
End With
End Sub
Public Function sndar(sendarray As Variant) As Byte()
sndar = sendarray
End Function