Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

IncludePicture Field use with VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean - 27 Aug 2004 21:17 GMT
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.
Jay Freedman - 28 Aug 2004 00:16 GMT
>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.

--
Regards,
Jay Freedman              http://aspnet2.com/mvp.ashx?JayFreedman
Microsoft Word MVP        FAQ: http://word.mvps.org
macropod - 31 Aug 2004 10:43 GMT
Hi Sean,

This can also be done by inserting a FILLIN field into the INCLUDEPICTURE
field. No vba required - unless you want to use
ActiveDocument.Fields.Update, but you could get the same result by printing
the document with 'update fields' checked, under Tools|Options|Print.

Cheers

> 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.
dynamictiger - 01 Jan 2006 00:41 GMT
I am intending adding photos to word from MS access code.  Your code

Code
-------------------
   ActiveDocument.Fields.Add _
 Range:=Selection.Range, _
 Type:=wdFieldIncludePicture, _
 Text:=wdQuote & strFN & wdQuote, _
 preserveformatting:=False

-------------------


works, however it is adding a field to my template which is not what
intended to do.

> 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.
>  

Defines exactly what I want to do.  

I have an existing picture acting as marker in my document, it i
inserted as an includepicture field.  This is the field that I want t
update with a picture from code.  I have attempted searching for hel
on this and have failed to find relevant references.  The closest i
your post.  Can you help please
Doug Robbins - Word MVP - 01 Jan 2006 11:15 GMT
Try adding a line

Selection.Range.Fields(1).Unlink

Or to add a picture to a document, you can use:

.Range.InlineShapes.AddPicture Filename:=strFN

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

> I am intending adding photos to word from MS access code.  Your code
>
[quoted text clipped - 23 lines]
> on this and have failed to find relevant references.  The closest is
> your post.  Can you help please?
dynamictiger - 01 Jan 2006 21:43 GMT
Thanks for your advice.

Selection.Range.Fields(1).Unlink - Is giving me an error on the wor
merge field doc and the the other doc I have set up without a field.
The error is "Not part of the collection".

.Range.InlineShapes.AddPicture Filename:=strFN - Works fine but i
still placing the picture at the top of the document not in th
predetermined picture box.

Is there something I am missing on the word side
Doug Robbins - Word MVP - 02 Jan 2006 04:47 GMT
You need to make a reference to the .Range into which you want the picture
to be inserted.

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

> Thanks for your advice.
>
[quoted text clipped - 7 lines]
>
> Is there something I am missing on the word side?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.