VBA Code to auto-insert hyperlinks between each row and each image

achortechie

New Member
Joined
May 14, 2013
Messages
1
Hi. Hoping VBA programmers out there can help!

I have several spreadsheet tabs in an Excel workbook
-each sheet needs to link to a unique folder of jpegs but hyperlinking done at the row level with EACH row linking up to a particular jpeg. Manual insertion of each link not an option for the following reasons:<o:p></o:p>

· There are thousands of images and manually inserting would not be cost-effective.<o:p></o:p>
· If the image folder locations change for whatever reason (we find a more permanent network spot or your server addresses change), the hyperlinks won’t work and relinking all of them would be required.<o:p></o:p>
· If we learn how to write the macro once, we can simply update the code for the change and it will save us time.<o:p></o:p>
· By knowing the code, we can alter it slightly for other similar projects and save ourselves much time and struggle.<o:p></o:p>
<o:p></o:p>
I never took a programming course in Visual Basic so was at a loss as to the coding but took a stab at it and got one piece of the code working properly. My code when “played” within the macro-creation tool does automatically insert hyperlinks into every row for that one sheet. However, I cannot get it to auto-increment the hyperlink address each time it inserts so basically every row has a link but they all link to the first jpeg, not to the remaining files (filenames go up by 1 in ascending order). My code utilizes a loop, which gets it to add links to each row one after another but that’s all it does as I’ve said. In the code below you'll see that I successfully got all 980 rows to contain a hyperlink to an image [network path of Z:\Photographs-Complete Collection\0504806000\JPEG\0504806000_001.jpg] but need to bump the 001.jpg to 002.jpg, 003.jpg etc etc. all the way to 980.jpg with each row ascending.

My code so far:

Dim rowTotal As Integer<o:p></o:p>
Dim fileNum As Integer<o:p></o:p>
fileNum = 1<o:p></o:p>
Do <o:p></o:p>
ActiveCell.Select<o:p></o:p>
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _<o:p></o:p>
"Z:\Photographs-Complete Collection\0504806000\JPEG\0504806000_001.jpg" _<o:p></o:p>
, TextToDisplay:= _<o:p></o:p>
"Click for Image"<o:p></o:p>
ActiveCell.Offset(1, 0).Select<o:p></o:p>
fileNum = fileNum + 1<o:p></o:p>
<o:p></o:p>
rowTotal = rowTotal + 1<o:p></o:p>
Loop Until rowTotal = 980<o:p></o:p>


 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,219
Messages
6,123,691
Members
449,117
Latest member
Aaagu

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