Antivirus getting in the way (1 Viewer)

standenman

Member
Local time
Today, 03:39
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.
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

  • screenshotforAccessForum.png
    screenshotforAccessForum.png
    183 KB · Views: 62
Last edited:

MarkK

bit cruncher
Local time
Today, 03:39
Joined
Mar 17, 2004
Messages
8,181
I don't understand your post.
You say the process works [fine] when the file is on your desktop, but the code you posted appears to download the file to your desktop. It is not clear, therefore, exactly when or where this problem occurs.
 

Users who are viewing this thread

Top Bottom