
Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
Doug,
Thank you for the information. The code snippet you provided does not make
the picture itself a hyperlink but rather creates a separate hyperlink line
when executed.
It seems to me that I need to use the Dialog.Display method, the add the
picture myself, as in
If PicDlg.Display = -1 Then
' add the picture to inline shapes
Shape1 = ActiveDocument.InlineShapes.AddPicture _
(FileName:=PicDlg.Name, LinkToFile:=False, SaveWithDocument:=True)
Then I would add the hyperlink as in
ActiveDocument.Hyperlinks.Add Anchor:=Shape1, Address:=FName, _
SubAddress:=""
However, when I try this I get the error message 'Object variable or With
block variable not set'. I've defined shape one as
Dim Shape1 As InlineShape
but unfortunately I do not know enough VB to understand the format of the
set statement for an inlineshape.
> The following lines of code are selecting the last picture in the document
> as i is being set to the count of the pictures.
[quoted text clipped - 60 lines]
> > SubAddress:=""
> > End If
Doug,
Thank you for the information. The code snippet you provided does not make
the picture itself a hyperlink but rather creates a separate hyperlink line
when executed.
It seems to me that I need to use the Dialog.Display method, the add the
picture myself, as in
If PicDlg.Display = -1 Then
' add the picture to inline shapes
Shape1 = ActiveDocument.InlineShapes.AddPicture _
(FileName:=PicDlg.Name, LinkToFile:=False, SaveWithDocument:=True)
Then I would add the hyperlink as in
ActiveDocument.Hyperlinks.Add Anchor:=Shape1, Address:=FName, _
SubAddress:=""
However, when I try this I get the error message 'Object variable or With
block variable not set'. I've defined shape one as
Dim Shape1 As InlineShape
but unfortunately I do not know enough VB to understand the format of the
set statement for an inlineshape.
> The following lines of code are selecting the last picture in the document
> as i is being set to the count of the pictures.
[quoted text clipped - 60 lines]
> > SubAddress:=""
> > End If
Strong Eagle - 07 Oct 2006 11:33 GMT
OK... I got it... code not as elegant as yours but it works
Dim PicDlg As Dialog
Dim i As Integer
Dim FName As String
Dim Shape1 As InlineShape
Dim Range1 As Range
Set fs = CreateObject("Scripting.FileSystemObject")
Set PicDlg = Dialogs(wdDialogInsertPicture)
If PicDlg.Display = -1 Then
' add the picture to inline shapes
Set Range1 = Selection.Range
Set Shape1 = ActiveDocument.InlineShapes.AddPicture _
(FileName:=PicDlg.Name, LinkToFile:=False, SaveWithDocument:=True, _
Range:=Range1)
' now move insertion point to end of picture just inserted
Range1.Collapse Direction:=wdCollapseStart
Range1.Move Unit:=wdCharacter, Count:=1
Range1.Select
' extract the filename from full path
FName = fs.GetFileName(PicDlg.Name)
' set a hyperlink with name and selection
ActiveDocument.Hyperlinks.Add Anchor:=Shape1, Address:=FName, _
SubAddress:=""
End If
> Doug,
>
[quoted text clipped - 87 lines]
> > > SubAddress:=""
> > > End If
Strong Eagle - 07 Oct 2006 11:34 GMT
OK... I got it... code not as elegant as yours but it works
Dim PicDlg As Dialog
Dim i As Integer
Dim FName As String
Dim Shape1 As InlineShape
Dim Range1 As Range
Set fs = CreateObject("Scripting.FileSystemObject")
Set PicDlg = Dialogs(wdDialogInsertPicture)
If PicDlg.Display = -1 Then
' add the picture to inline shapes
Set Range1 = Selection.Range
Set Shape1 = ActiveDocument.InlineShapes.AddPicture _
(FileName:=PicDlg.Name, LinkToFile:=False, SaveWithDocument:=True, _
Range:=Range1)
' now move insertion point to end of picture just inserted
Range1.Collapse Direction:=wdCollapseStart
Range1.Move Unit:=wdCharacter, Count:=1
Range1.Select
' extract the filename from full path
FName = fs.GetFileName(PicDlg.Name)
' set a hyperlink with name and selection
ActiveDocument.Hyperlinks.Add Anchor:=Shape1, Address:=FName, _
SubAddress:=""
End If
> Doug,
>
[quoted text clipped - 87 lines]
> > > SubAddress:=""
> > > End If