VBA to follow hyperlinks to different files and save in alt folder

Randall83

New Member
Joined
Nov 16, 2015
Messages
5
I have a workbook with a column of 1000+ hyperlinks that link to numerous files of different types in numerous different folder locations on one drive and I want to automate the process of saving those documents to one folder location using the adjacent cell as the file name. There will be a mix of doc types .jpg, .docx, .doc, .pdf, .xls etc - if they can be processed at the same time that would be great however if I have to have a VBA for each doc type I don't mind.


I have searched for solutions to this issue however the closest I had found was for opening workbooks in excel and using saveas to save as a single doc type and having to split each doc type to its own sheet in the workbook. This solution was opening all file types as if it were an .xlsx file and saving it as a .jpg (for example) so obviously corrupting the file.


Code:
Sub test()

Dim hlink As Hyperlink
Dim wb As Workbook
Dim saveloc As String
saveloc = "C:\My Documents\"
For Each hlink In ThisWorkbook.Sheets("jpg").Hyperlinks
    Set wb = Workbooks.Open(hlink.Address)
    wb.SaveAs saveloc & hlink.Range.Offset(0, 1).Value & ".jpg"
    wb.Close True
    Set wb = Nothing
Next

End Sub



Any ideas on how I can achieve this?


Many thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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