Thursday, 1 October 2015

VBA to download and save excel file from website, also copy the contents to new file

Sub Download_File()

Windows("Example.xlsm").Activate ' activate your specific macro file

Dim file As String
Dim path As String
path = "Path where you want to save the file"  ' Example:-  C:\Test\
file = "Path of the file that you want to download" ' Example : -

ThisWorkbook.FollowHyperlink file ' parsing file URL
With ActiveWorkbook
.SaveAs path & "new.csv"  ' altering file name and type to the location

.ActiveSheet.Range("A:C").Copy  ' Copying the data of column A - C from the downloaded file
Application.DisplayAlerts = False ' Alerts disabled to ensure file is closed without any prompt message
Application.DisplayAlerts = True

End With

Windows("Example.xlsm"). ' re activate your specific macro file
ActiveSheet.Range("a1").Select  ' select and paste the copied data
Range("a1").PasteSpecial xlPasteAll

End Sub

No comments:

Post a Comment