Article ID: 182173
Article Last Modified on 6/17/2005
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
181058 OFF98: 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 kbnofix kbmacroexample kbdtacode KB182173