A family of Microsoft word processing software products for creating web, email, and print documents.
Thanks, Andreas--I'll try your modification out and see if that changes anything.
Christian
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
So Word's built-in "Insert Hyperlink" feature in Word 2002 is awful, and it does not appear to have changed in Word 2007 or 2010 either. In short, it forces you to insert each hyperlink individually, and each time you select the option from the menu, it gives you a file dialog that has no memory of the last place you navigated to. This makes it an ABSOLUTE PAIN to insert, say, hyperlinks to 5 documents located in a directory structure which is 5 levels deep--at least 25 clicks are involved. To me, it is incomprehensible that multi-pick functionality and previous working directory memory functionality was not included from the get-go. It is criminal that this is still the case in 2010.
Given that Microsoft appears to think this isn't worth addressing, I figured I'd just write my own code, which is included below.
It works phenomenally well, until it inexplicably causes an "Out of Memory" error and dies. I want to know what I'm doing wrong or why it would do this. Some additional background facts:
a) If you insert a hyperlink using VBA while in the middle of a pre-existing hyperlink, you'll crash. Thus, I have code to prevent such occurences.
b) If you have Word as your email editor, then the macro works there as well. But sometimes it won't paste it into the current email document, but into whatever document is currently active in Word (which doesn't seem like the "current" document if you're currently editing an email).
c) The "Out of memory" error appears to be entirely random. Some days, I can use it all day without issue. Others, it crashes within minutes.
Cheers,
Christian
Sub InsertMultiHL_PathLbl()
Dim fd As FileDialogSet fd = Application.FileDialog(msoFileDialogFilePicker)
Dim SelectedFile As VariantWith fd If .Show = -1 Then Application.ActiveWindow.Selection.Collapse If Application.ActiveWindow.Selection.Hyperlinks.Count >= 1 Then MsgBox "Insertion Point Cannot Be Within Preexisting Hyperlink!" Else For Each SelectedFile In .SelectedItems Application.ActiveWindow.Document.Hyperlinks.Add Anchor:=Selection.Range, _ Address:=SelectedFile, _ SubAddress:="", _ ScreenTip:="", _ TextToDisplay:=SelectedFile Application.ActiveWindow.Selection.TypeParagraph Next SelectedFile End If Else End IfEnd WithSet fd = Nothing
End Sub
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Thanks, Andreas--I'll try your modification out and see if that changes anything.
Christian
Hi Gerry,
I'm afraid I don't understand the relevance of the 3 "buts" above to the issue I am having.
3) I'm not sure why this is a big disadvantage. Do you mean "folder"? If so, I agree--inserting a folder as a hyperlink would be nice.
a) If you insert a hyperlink using VBA while in the middle of a pre-existing hyperlink, you'll crash. Thus, I have code to prevent such occurences.
Whilst it is unlikely to be what you want, and having code to suppress it is probably wise, this is possible and should not crash Word. That it does, and the fact that you have other errors suggests either (a) a misbehaving AddIn or (b) a faulty installation of Word.
To see if it is the former, try running your code with Word in Safe Mode (press and hold Ctrl while starting Word). Otherwise, try repairing your installation of Word (Office button > Word Options > Resources tab > Diagnose)
Enjoy,
Tony
I am not sure either why you would get an Out of Memory error. Something else must be going on.
True, your procedure allows you to insert multiple hyperlinks. But...
1. you can not change the display text (unless you add another dialog, an InputBox say?)
2. you can not use multiple locations (all the files must be from the same folder)
3. you can only use files, you can not use bookmarks as a Target
Gerry Word MVP
Am 23.12.2010 01:11, schrieb Christianovitch:
It works phenomenally well, until it inexplicably causes an "Out of Memory" error and dies. I want to know what I'm doing wrong or why it would do this.
I have not realy an idea whats wrong, but I think there is no need to use ActiveWindow.
Andreas.
Sub InsertMultiHL_PathLbl()
Dim SelectedFile As Variant
If Selection.Hyperlinks.Count >= 1 Then
MsgBox "Insertion Point Cannot Be Within Preexisting Hyperlink!"
Exit Sub
End If
With Application.FileDialog(msoFileDialogFilePicker)
If .Show = -1 Then
For Each SelectedFile In .SelectedItems
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=SelectedFile, _
SubAddress:="", _
ScreenTip:="", _
TextToDisplay:=SelectedFile
Selection.TypeParagraph
Next
End If
End With
End Sub