Outlook: ต้องการดาวน์โหลดไฟล์จาก Hyperlink ใน Sub-Folder อัตโนมัติ
Posted: Fri Oct 08, 2021 1:54 pm
สวัสดีครับ
ผมได้รับ Auto email จากระบบทุกวันแต่ปัญหาคือได้รับเป็น hyperlink ไม่ใช่ file ครับ
จึงอยากสอบถามพี่ๆ พอจะมีวิธีให้ดาวน์โหลดไฟล์ทุกไฟล์จาก Subfolderใน Outlook ที่ผมตั้งให้เมลเข้าไว้ มาสู่ Specific folder ในคอมพิวเตอร์มั้ยครับ ?
ด้านล่างคือ Codeที่ผมลอง แต่มันจะใช้ได้กับลิงค์เดียวครับ
Option Explicit
Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Sub DownloadFile()
Dim WinHttpReq As Object
Dim oStream As Object
Dim myURL As String
Dim LocalFilePath As String
'myURL = "http://th.app.xpress.com/WebPortal/Auto ... 676cf37ec3"
'LocalFilePath = "C:\Users\OChaowana\Desktop\Volume Hourly\PQ\TST\TEST.xlsx"
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "", "" '("username", "password")
WinHttpReq.Send
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile LocalFilePath, 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If
End Sub
ผมได้รับ Auto email จากระบบทุกวันแต่ปัญหาคือได้รับเป็น hyperlink ไม่ใช่ file ครับ
จึงอยากสอบถามพี่ๆ พอจะมีวิธีให้ดาวน์โหลดไฟล์ทุกไฟล์จาก Subfolderใน Outlook ที่ผมตั้งให้เมลเข้าไว้ มาสู่ Specific folder ในคอมพิวเตอร์มั้ยครับ ?
ด้านล่างคือ Codeที่ผมลอง แต่มันจะใช้ได้กับลิงค์เดียวครับ
Option Explicit
Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Sub DownloadFile()
Dim WinHttpReq As Object
Dim oStream As Object
Dim myURL As String
Dim LocalFilePath As String
'myURL = "http://th.app.xpress.com/WebPortal/Auto ... 676cf37ec3"
'LocalFilePath = "C:\Users\OChaowana\Desktop\Volume Hourly\PQ\TST\TEST.xlsx"
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "", "" '("username", "password")
WinHttpReq.Send
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile LocalFilePath, 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If
End Sub