Dear all,
I am a VBA novice trying to write code to insert a picture and the filename as a caption. By surfing the net to find example macros and piecing together the relevant bits, here's what I've come up with so far:
[VBA] Sub InsertPicture()
Dim Doc As Dialog
Dim BClicked As String
Dim picPath As String
Dim picName As String
Dim oRg As Range
Set Doc = Dialogs(wdDialogFileOpen)
With Doc
.Name = "*.jpg"
BClicked = .Display
picName = .Name 'picName holds the picture name
End With
picPath = CurDir 'picPath holds the picture path
Selection.InlineShapes.AddPicture FileName:=picPath & "\" & picName
Selection.InsertCaption Label:="Figure", TitleAutoText:="", Title:=": " & picName, _
Position:=wdCaptionPositionBelow
End Sub
[/VBA]
I have two problems:
1. If I try to insert a picture with a filename that contains spaces then I get a run-time error '5152'.
2. The code 'Position:=wdCaptionPositionBelow' positions the caption at the bottom right of the picture but I would prefer it to be underneath it.
Does anyone have any ideas or suggestions? Any help would be much appreciated.
Thanks,
Andrew