S
Strong Eagle
Hello All,
I have created a macro which uses the insert picture dialog and then
automatically creates a hyperlink for the picture using the name taken from
the insert picture dialog box.
The problem is that I can only insert pictures at the end of the document.
If I attempt to insert a picture using the macro between already inserted
pictures, the hyperlink is added at the end of the hyperlink list and then
the two lists are out of order.
In other words, I cannot figure out how to search for the correct item in
the hyperlink list so that I can insert in the middle of the list.
The code I am using is posted below (VB). Would much appreciate assistance
in making this more robust... ability to insert a picture into the middle of
already inserted pictures, change a picture, or delete an inserted picture.
Many thanks.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/27/2005 by Wayne Herbert
'
Dim PicDlg As Dialog
Dim i As Integer
Dim FName As String
Dim Shape1 As InlineShape
Set fs = CreateObject("Scripting.FileSystemObject")
Set PicDlg = Dialogs(wdDialogInsertPicture)
If PicDlg.Show = -1 Then
' get the index of last picture added and select it
i = ActiveDocument.InlineShapes.Count
ActiveDocument.InlineShapes.Item(i).Select
' extract the filename from full path
FName = fs.GetFileName(PicDlg.Name)
' set a hyperlink with name and selection
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=FName, _
SubAddress:=""
End If
I have created a macro which uses the insert picture dialog and then
automatically creates a hyperlink for the picture using the name taken from
the insert picture dialog box.
The problem is that I can only insert pictures at the end of the document.
If I attempt to insert a picture using the macro between already inserted
pictures, the hyperlink is added at the end of the hyperlink list and then
the two lists are out of order.
In other words, I cannot figure out how to search for the correct item in
the hyperlink list so that I can insert in the middle of the list.
The code I am using is posted below (VB). Would much appreciate assistance
in making this more robust... ability to insert a picture into the middle of
already inserted pictures, change a picture, or delete an inserted picture.
Many thanks.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/27/2005 by Wayne Herbert
'
Dim PicDlg As Dialog
Dim i As Integer
Dim FName As String
Dim Shape1 As InlineShape
Set fs = CreateObject("Scripting.FileSystemObject")
Set PicDlg = Dialogs(wdDialogInsertPicture)
If PicDlg.Show = -1 Then
' get the index of last picture added and select it
i = ActiveDocument.InlineShapes.Count
ActiveDocument.InlineShapes.Item(i).Select
' extract the filename from full path
FName = fs.GetFileName(PicDlg.Name)
' set a hyperlink with name and selection
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=FName, _
SubAddress:=""
End If