MS Word Hyperlink to Files Located in Same Folder as Document

1

I want to setup hyperlinks in a Word document to files (jpg) that are always located in the same folder as the Word Document

I want to distribute a package of the Word document plus the supporting jpg files to people who may put the files anywhere on a computer or server.

I want the hyperlinks to work anywhere

Maybe VBA code something like

On click hyperlink determine the location of the document file and link to (open) the specified jpg file in that location

Many thanks

Greg Mules

Posted 2014-12-03T06:11:09.583

Reputation: 11

So are you looking for how to create the hyperlinks or VBA code in Word that will find the files anywhere the recipient puts them? Is it a requirement that the recipient be able to separate the files and put them somewhere else (or is that just a situation you are trying to deal with because you don't have a good way to ensure they will be kept together)? – fixer1234 – 2014-12-03T06:24:41.823

Answers

0

In terms of what to put into the Word Doc to bring up the JPGs, I would use form controls instead of hyperlinks:

First, in Word, enable the Developer tab on the Ribbon:

  1. Click the little 'down triangle' next to the Quick Access Toolbar and select 'More Commands.'

Word snip

  1. Select 'Customize Ribbon', then ensure that the checkbox next to 'Developer' under 'Customize the Ribbon' is checked. Click OK to close.

Word snip

Now, insert and configure the command buttons:

  1. Select the Developer tab from the Ribbon, then click 'Legacy Tools' from the 'Controls' block, and then select 'Command Button'

Word snip

  1. Draw as many buttons as you have JPG files to open. These can be dragged and dropped to wherever in the document you need them, though you may have to change the text wrapping style (right-click, 'Format Control', 'Layout' tab)

  2. To change the text displayed on each button, as well as the code name for each, right-click one button and select 'Properties'

  3. Single left-click each button in turn and set the '(name)' and 'Caption' fields of the Properties box to the code name (e.g., BtnThisPic and BtnThatPic) and display text (e.g., "Click to open This Pic" and "Click to open That Pic"), respectively.

  4. Double-left-click each button in turn, and insert the following code into the _Click event handler method that should be auto-generated for each:

    Dim sh As New Shell  
    sh.ShellExecute ThisDocument.Path & "\picname.jpg"
    

Finally, add the 'Microsoft Shell Controls and Automation' Reference to the file:

  1. In the VBA Editor, click 'Tools' > 'References'
  2. In the References box that pops up, scroll (way, way) down until you find the MSCA reference, check its checkbox, and click 'OK'

VBA Editor snip

Save the Word doc and give the command buttons a click. If all has gone well, the appropriate images should open as desired.

(If at any point it won't let you right-click the buttons or otherwise edit them, make sure 'Design Mode' is activated on the 'Developer' tab of the 'Ribbon', in the 'Controls' block.)

hBy2Py

Posted 2014-12-03T06:11:09.583

Reputation: 2 123