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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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