IncludePicture with variables?
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
IncludePicture with variables?
Hi All!
In my latest escapade I'm trying to dynamically change an image in a document based on what the user selects in a form.
Currently I have a fieldcode in the template that looks like this: INCLUDEPICTURE "http://Link to sharepoint/Images/ {DocVariable MyImage}" \* MERGEFORMAT
And in my form code I set MyImage to the name of the image: ActiveDocument.Variables("MyImage") = lblMyImage (where lblMyImage would contain img1.gif or whatever the user selects in the form from a dropdown box)
This works just fine, as long as the main location of the image doesn't change. BUT the image can come from several different locations, which might be a different Sharepoint location or a network drive, so I wanted the whole path to be a docvariable. Word doesn't like this, though, and when I try to change the whole thing to a docvariable, Word inserts a dummy path to my C: drive, which is not what I want at all. Nothing I do can change Word's mind that the c:\\MyImage\\ whatever is not what I want.
Is there a different way to accomplish a completely variable image name/path?
(I also couldn't get the image to dynamically change on the form, but I'd rather sort this part out first since it's more critical to the document.)
In my latest escapade I'm trying to dynamically change an image in a document based on what the user selects in a form.
Currently I have a fieldcode in the template that looks like this: INCLUDEPICTURE "http://Link to sharepoint/Images/ {DocVariable MyImage}" \* MERGEFORMAT
And in my form code I set MyImage to the name of the image: ActiveDocument.Variables("MyImage") = lblMyImage (where lblMyImage would contain img1.gif or whatever the user selects in the form from a dropdown box)
This works just fine, as long as the main location of the image doesn't change. BUT the image can come from several different locations, which might be a different Sharepoint location or a network drive, so I wanted the whole path to be a docvariable. Word doesn't like this, though, and when I try to change the whole thing to a docvariable, Word inserts a dummy path to my C: drive, which is not what I want at all. Nothing I do can change Word's mind that the c:\\MyImage\\ whatever is not what I want.
Is there a different way to accomplish a completely variable image name/path?
(I also couldn't get the image to dynamically change on the form, but I'd rather sort this part out first since it's more critical to the document.)
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
If you want to refer to an image om a local hard disk or network drive, you should double the backslashes in the path, e.g. if the image is C:\Pictures\Blossom.jpg, your document variable should be set to C:\\Pictures\\Blossom.jpg. You can then use
{ INCLUDEPICTURE "{ DOCVARIABLE MyImage }" }
Remember, never type the { } yourself, use Ctrl+F9 to insert them.
{ INCLUDEPICTURE "{ DOCVARIABLE MyImage }" }
Remember, never type the { } yourself, use Ctrl+F9 to insert them.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
harumph.HansV wrote:If you want to refer to an image om a local hard disk or network drive, you should double the backslashes in the path, e.g. if the image is C:\Pictures\Blossom.jpg, your document variable should be set to C:\\Pictures\\Blossom.jpg. You can then use
{ INCLUDEPICTURE "{ DOCVARIABLE MyImage }" }
Remember, never type the { } yourself, use Ctrl+F9 to insert them.
I didn't type the {} myself, but when I redid it, it saved properly. But now I seem to have a different problem.
For a network folder, I know it has to be \\ instead of \. But for Sharepoint/Intranet, I was able to use http://my" onclick="window.open(this.href);return false; sharepoint site/image.gif. When I did it as a variable, no such luck. So do I need to make the / as //, and if so, do I need to make http:// into http:////? gonna go test.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
With web addresses (http://.." onclick="window.open(this.href);return false;.), the forward slashes do NOT need to be doubled. It works OK for me if I set the document variable to something like http://www.mysite.com/pictures/mypicture.jpg" onclick="window.open(this.href);return false;. I cannot test on SharePoint but it should be the same though.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
Yeah, intranet and sharepoint are the same.HansV wrote:With web addresses (http://.." onclick="window.open(this.href);return false;.), the forward slashes do NOT need to be doubled. It works OK for me if I set the document variable to something like http://www.mysite.com/pictures/mypicture.jpg" onclick="window.open(this.href);return false;. I cannot test on SharePoint but it should be the same though.
I'm getting really frustrated, as it's not working with intranet OR network folder. If I use the toolbar to enter the codes, MS defaults it to c:\\ etc (and no doc variable supplied) when I go to save the template, so basically I can't save it that way. If I use <ctrl>F9 and enter the codes manually, they don't work, and I don't get any image, just an error when I go to run it. If I cut/paste the address in and don't use a variable, it works.
Edit: Let me revise that. The reason it didn't work when I got the field codes in properly was that I didn't actually get the field codes in properly, I typed wrong (of course!). My problem is that if I use INCLUDEPICTURE it always changes to c:\\ etc when I go to save the template. I don't know how to get it to stop doing that!!! What a pain!
Last edited by Cecilia on 31 Mar 2011, 19:52, edited 1 time in total.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
That's strange - I tested with the document variable set to a file path (double backslashes) and to an internet path (single forward slashes), and a field with code { INCLUDEPICTURE "{ DOCVARIABLE MyImage }" }. Both worked OK, and remained OK after saving, closing and reopening the document.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
Yeah, I just realized that my field code was wrong. The big problem for me is getting the template to save without it prepending c:\\ etc (pointing to my desktop). It doesn't want to save with *just* the docvariable there.HansV wrote:That's strange - I tested with the document variable set to a file path (double backslashes) and to an internet path (single forward slashes), and a field with code { INCLUDEPICTURE "{ DOCVARIABLE MyImage }" }. Both worked OK, and remained OK after saving, closing and reopening the document.
I think I'm about to lose my mind on this :(
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
I'm very sorry, I can't explain the behavior that you experience.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
I'm trying to make a list of things that would cause Word to update a variable on save. I went through the stuff under Tools-->Options, Print tab and unchecked just about everything. Any other ideas would be appreciated greatly.HansV wrote:I'm very sorry, I can't explain the behavior that you experience.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
It really shouldn't be necessary to do that.
Does the problem persist if you restart your PC?
You could try starting a "bare" version of Word:
- Press Windows key+R to activate the Run dialog.
- Type winword /a and press Enter or click OK.
- Word starts without loading Normal.dot or any global templates/add-ins.
- See if the INCLUDEPICTURE field behaves correctly now.
Does the problem persist if you restart your PC?
You could try starting a "bare" version of Word:
- Press Windows key+R to activate the Run dialog.
- Type winword /a and press Enter or click OK.
- Word starts without loading Normal.dot or any global templates/add-ins.
- See if the INCLUDEPICTURE field behaves correctly now.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
None of that helped, and I've tried it on two different computers.HansV wrote:It really shouldn't be necessary to do that.
Does the problem persist if you restart your PC?
You could try starting a "bare" version of Word:
- Press Windows key+R to activate the Run dialog.
- Type winword /a and press Enter or click OK.
- Word starts without loading Normal.dot or any global templates/add-ins.
- See if the INCLUDEPICTURE field behaves correctly now.
BTW, all I have to do is prepend the DocVariable with c:\\ and it doesn't change when I go to save.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
BTW I tested using Word 2007 right now, but in the past, I have used this technique without problems in Word 2000, 2002 and 2003 too...
I hope that someone else will be able to shed some light on this.
I hope that someone else will be able to shed some light on this.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
I really do appreciate your help, Hans.
I'm wondering, though, is there a different way I could do this? (insert a picture into a specific place in a Word document)?
I'm wondering, though, is there a different way I could do this? (insert a picture into a specific place in a Word document)?
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
INCLUDEPICTURE is the way to do this, I don't know of another way...
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
Wholly crow! Just as I was about to give up...http://help.lockergnome.com/office/Incl ... 49037.html" onclick="window.open(this.href);return false;
From the Tools menu, select Options and then on the General tab, click on
Web Options and then select the Files tab and uncheck the option to Update
links on save.
From the Tools menu, select Options and then on the General tab, click on
Web Options and then select the Files tab and uncheck the option to Update
links on save.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
The option "Update links on save" is ticked in my version of Word, and the INCLUDEPICTURE fields still behave correctly.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 89
- Joined: 19 Feb 2010, 16:56
- Location: San Francisco, Alameda, CA
Re: IncludePicture with variables?
Is this in 2007 or 2003? I'm using 2003.
I dunno. It worked to fix my problem. If you don't think it's helpful, maybe delete this thread? I updated it just in case someone else got stuck with the same (frustrating) problem.
I dunno. It worked to fix my problem. If you don't think it's helpful, maybe delete this thread? I updated it just in case someone else got stuck with the same (frustrating) problem.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: IncludePicture with variables?
I'm currently using Word 2007.
If it works for you, it might be useful to others too!
If it works for you, it might be useful to others too!
Best wishes,
Hans
Hans