PDA

View Full Version : Hyperlinking From a Word UserForm



MWE
04-08-2006, 08:33 AM
I appear to be having trouble hyperlinking from a word userform to another file. Sub A loads and shows UserForm B. The onclick code for button C in B builds a hyperlink address and then uses the FollowHyperlink method to hyperlink to the target file. ActiveDocument.FollowHyperlink Address:=strAddressThis does not work. I get an error code 287, "Application-defined, or object-defined error". The address is correct.

However, if I move the exact same code from B's code module to a spot right after A loads and shows B (thus the hyperlink is starting from A vs from B), everything works fine.

I hyperlink out of Forms in other applications (particularly Excel) without this problem.

Is this problem unique to Word or is this perhaps just another problem with my version of Word/VBA

fumei
04-08-2006, 07:22 PM
Please...how can we really see what is going on if you do not post code? It sounds like it is a matter of SCOPE...but without code, shrug....whatever.

MWE
04-09-2006, 12:26 PM
Please...how can we really see what is going on if you do not post code? It sounds like it is a matter of SCOPE...but without code, shrug....whatever.The question is really one about what limitations, if any, are there to hyperlinking out of a UserForm in Word. The code that is in the userformB's code module and does not work:
Private Sub cmdBtnHelp_Click()
Dim strAddress As String
strAddress = gblHelpFile
ActiveDocument.FollowHyperlink Address:=strAddress
End Sub

gblHelpFile is a global that contains the path and name of the file to be opened.

When that same code is placed in Sub A (that loads and shows UserFormB), it works fine.

fumei
04-09-2006, 02:42 PM
You state in the first post that you "build" the hyperlink. then follow it. Your code does not do this. Your code explicitly calls an instruction to follow an explicitly given address. There is no building of a link in the document. The code given will jump regardless of ANY content in the document. It works with a perfectly blank document.

Further, I have no problem making this fire from a commandbutton on a userform. As far as I know there are no limitations for such instructions. Are you positive it is not a matter of scope? It kind of sounds like it is. Your global is correctly declared, in scope? If it is properly in scope...then I don't know what to say, except that, again, your install of Word is very very funky.