standenman
Member
- Local time
- Yesterday, 21:35
- Joined
- May 12, 2016
- Messages
- 45
I am trying to create VBA code that will download a template pdf file from my online adobe acrobat account and fill it with MS Access data. It works file when I have the target file on my desktop.
BitDefender will not let me run it. Any ideas?
Code:
Private Sub Command85_Click()
Dim TemplateURL As String
Dim DownloadFolder As String
Dim DownloadPath As String
' Define the URL of your Adobe Acrobat template
TemplateURL = "url to my pdf template"
' Define the folder where you want to save the downloaded template
DownloadFolder = "C:\Users\stand\Desktop\"
' Generate a unique file name
DownloadPath = DownloadFolder & "template_" & Format(Now, "YYYYMMDDHHMMSS") & ".pdf"
' Download the template from the URL
If DownloadFile(TemplateURL, DownloadPath) Then
' Open the downloaded PDF in Adobe Acrobat
Shell "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe """ & DownloadPath & """", vbNormalFocus
Else
MsgBox "Template download failed."
End If
End Sub
Function DownloadFile(URL As String, FilePath As String) As Boolean
On Error Resume Next
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("MSXML2.ServerXMLHTTP")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send
If WinHttpReq.status = 200 Then
Dim objStream As Object
Set objStream = CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.Write WinHttpReq.responseBody
objStream.Position = 0
objStream.SaveToFile FilePath
objStream.Close
DownloadFile = (Err.Number = 0) ' Check if an error occurred during the save operation
End If
Set WinHttpReq = Nothing
On Error GoTo 0
End Function
BitDefender will not let me run it. Any ideas?
Attachments
Last edited: