Sean said:
Is it possible to set an IncludePicture field in a
document and the set the path as a variable that could be
changed by using code? If so what would the code look
like to add the field with a variable as the Filename?
Thanks.
Hi Sean,
This is just a little demo. Notice that if the filename in the field
code contains any backslashes, they have to be doubled.
Sub foo()
Dim strFN As String
Const wdQuote = """"
' There are many ways to get the
' filename of the picture. This is
' the worst for the user, but short code.
strFN = InputBox$("Enter picture's filename")
strFN = Replace(strFN, "\", "\\")
If Len(strFN) > 0 Then
ActiveDocument.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldIncludePicture, _
Text:=wdQuote & strFN & wdQuote, _
preserveformatting:=False
End If
End Sub
If you mean that you want to have the field include one picture now
and change that (in the same document) to a different picture later,
that's another story... then you want to display field codes and do a
find/replace of the old filename with the new one.