Article ID: 165923
Article Last Modified on 1/19/2007
Sub DoInLineShapeHyperlink()
Dim oDoc As Document
Dim oILPic As InlineShape
Dim oHLink As Hyperlink
Dim sPicFile As String
Dim sLinkFile as String
sPicFile = "<Your Graphic File Path and Name>"
sLinkFile = "<Your HyperLink File Path and Name>"
' Create new document.
Set oDoc = Documents.Add
' Insert a picture.
Set oILPic = oDoc.InlineShapes.AddPicture _
(Range:=oDoc.Content, FileName:=sPicFile, LinkToFile:=True)
' Add a hyperlink for the picture.
oDoc.Hyperlinks.Add Anchor:=oILPic.Range, Address:=sLinkFile
' The error occurs here because oILPic is no longer valid.
Set oHLink = oILPic.Hyperlink
End Sub
Private Sub DoInLineShapeHyperlink()
Dim oDoc As Document
Dim oILPic As InlineShape
Dim oHLink As Hyperlink
Dim sPicFile As String
Dim sLinkFile as String
sPicFile = "<Your Graphic File Path and Name>"
sLinkFile = "<Your HyperLink File Path and Name>"
' Create new document.
Set oDoc = Documents.Add
' Insert a picture.
Set oILPic = oDoc.InlineShapes.AddPicture _
(Range:=oDoc.Content, FileName:= sPicFile, LinkToFile:=True)
' Add a hyperlink for the picture.
oDoc.Hyperlinks.Add Anchor:=oILPic.Range, Address:=sLinkFile
' Use the InlineShapes Property to reference the object.
Set oHLink = oDoc.InlineShapes(1).Hyperlink
End Sub
Sub testObject()
Dim ilShp As InlineShape
Set ilShp = ActiveDocument.InlineShapes.Add("C:\Windows\bubbles.bmp")
MsgBox IsObjectValid(ilShp) ' This will display True
a.Delete
MsgBox IsObjectValid(ilShp) ' This will display False
End Sub
For additional information, please see the following article in the
Microsoft Knowledge Base:
173707 OFF97: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vba vbe
Keywords: kbbug kberrmsg kbmacroexample kbnofix kbprogramming kbusage KB165923