Indsætte billede med caption i word med brug af VBA
Jeg vil gerne indsætte et billede word med filnavn som caption.Jeg har fundet nedenstående kode som virker fint med undtagelse af den sidste linie, indsætte caption:
Selection.InsertCaption Label:="Figure", TitleAutoText:="", Title:=": " & picName, _
Position:=wdCaptionPositionBelow
Her kommer runtime error 4198
Jeg har prøvet både i word 2003 og 2007.
KODEN:
http://www.vbaexpress.com/forum/archive/index.php/t-6100.html
Option Explicit
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.TypeParagraph
Selection.InsertCaption Label:="Figure", TitleAutoText:="", Title:=": " & picName, _
Position:=wdCaptionPositionBelow
End Sub
Også så simpel kode som
Selection.InsertCaption Label:="noget tekst"
fejler !!?