Excel VBA navigating to hyperlink that downloads file and saving file

heavican03

New Member
Joined
Sep 29, 2015
Messages
3
I have a vba macro that is navigating to a hyperlink and downloading a file that is then saved. The only problem I am having with it is I can't get it to stop bringing up the Microsoft office warning that the file might contain harmful files. Can you help?

Code:
Sub LinkAndCopy()
     
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
     
     
    ThisWorkbook.FollowHyperlink Address:="http://cts/Tacs/LDCOperationDrillExport/762"
     
    ActiveWorkbook.SaveAs "C:\Users\q6bxh0\Documents\downloads\file.xlsx"
     ActiveWorkbook.Close
     
     
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
     
     
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I have a vba macro that is navigating to a hyperlink and downloading a file that is then saved. The only problem I am having with it is I can't get it to stop bringing up the Microsoft office warning that the file might contain harmful files. Can you help?

Code:
Sub LinkAndCopy()
     
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
     
     
    ThisWorkbook.FollowHyperlink Address:="http://cts/Tacs/LDCOperationDrillExport/762"
     
    ActiveWorkbook.SaveAs "C:\Users\q6bxh0\Documents\downloads\file.xlsx"
     ActiveWorkbook.Close
     
     
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
     
     
End Sub
Hi heavican03, welcome to the boards.

Here is the code I used for downloading from a URL which I have tweaked to suit your example above. This code has no popup warnings beyond my own custom "File Downloaded" message to confirm the action was completed, but this can simply be deleted from the end.

Code:
Sub Download_CSV()
Application.ScreenUpdating = False
    Dim myURL As String
    myURL = "http://cts/Tacs/LDCOperationDrillExport/762"
    
    Dim WinHttpReq As Object
    Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
    WinHttpReq.Open "GET", myURL, False
    WinHttpReq.Send
    
    myURL = WinHttpReq.ResponseBody
    If WinHttpReq.Status = 200 Then
        Set oStream = CreateObject("ADODB.Stream")
        oStream.Open
        oStream.Type = 1
        oStream.Write WinHttpReq.ResponseBody
        oStream.SaveToFile ("C:\Users\q6bxh0\Documents\downloads\file.xlsx"), 2
        oStream.Close
    End If
    MsgBox "File Downloaded"
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,206
Messages
6,129,496
Members
449,512
Latest member
Wabd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top