PDA

View Full Version : try to insert picture with docvariable



daniel76
04-24-2008, 11:33 PM
Hi,

I was trying to insert picture by using DOCVARIABLE to a word document in VBA but to no avail. Would anyone be able to share your ideas with me on this?

I have been looking for "addpicture" under activedocument.variables("blah") but could not find one.

I use office 03.

Thank you in advance

shasur
04-25-2008, 02:33 AM
You cannot add the picture to the variable. You can store the path and use it later:


Sub Add_Doc_Var()
ActiveDocument.Variables.Add "LogoPic", "c:\temp\sample.jpg"
End Sub

fumei
04-25-2008, 11:27 AM
I must point out that the value of the variable, in the code above, is the string "c:\temp\sample.jpg".

Not a image file.

You can not have an image file itself as a DOCVARIABLE. I think Shasur was suggesting this as a method of retrieving the path to the file from the DOCVARIABLE. I am not sure of how much use that would be...but I suppose it could be.

There is an AddPicture method. It applies to Shape, InlineShape, and CanvasShape objects.

Why are you trying to insert the image file by code?

daniel76
04-27-2008, 04:32 PM
Thank you to you both, Gerry and Shasur for your replies.

The reason for using codes to insert picture into variable is that this is actually for a report document. In the covering page or the first page of the report, we can have a choice of a plain text or an image of the company's logo.

So, i have a userform made up to allow this to happen. When the template is double-clicked, a new document is brought up as well as the userform. User can choose the options of whether to have just a plain text or an image.

If i use bookmarks, it still works. However, the problem is that the template also allows user to edit via the same userform. All the data entered into the document are to be put back into the form. If some bookmarks happen to be empty, then i'm running into trouble as it tries to look for bookmarks that do not exist already. So, it's kinda dilemma to me.

If there are any other ways out, i'm more than happy to consider.

Thank you in advance

lucas
04-27-2008, 07:09 PM
If some bookmarks happen to be empty, then i'm running into trouble as it tries to look for bookmarks that do not exist already.

If you have bookmarks that exist but are empty then they should just return empty or blank.

How are you managing your bookmarks entry and retrieval. It seems like you are having a little trouble so I will suggest that Gerry, Malcolm, TonyJollins and others here at the forum have fine tuned managing data input and editing using bookmarks.

Here is one thread that might interest you:
http://www.vbaexpress.com/forum/showthread.php?t=11427

I attached a sample to this post so you can see how it works. Let me know if you are happy with what you are doing and don't need this.....its just a suggestion that I once found useful and have been using ever since.


Gerry pointed out that there is probably a better way to handle the pictures than putting them in programmatically. Why can't the picture already be in the template?

Here is a link to a thread that discusses creating multiple templates in one .dot file. Each is in a bookmark and when a selection is made from the userform all of the bookmarks are deleted except your choice.
http://vbaexpress.com/forum/showthread.php?t=13543

Just some options until you can tell us what is going on with your bookmarks.....

Edit: Second link corrected.....thanks for catching that Gerry.

fumei
04-28-2008, 03:47 AM
Yes, this should not be a problem.

Frankly, I would simply put the logo in the template as an AutoText.

BTW: this is a reason?????

"The reason for using codes to insert picture into variable is that this is actually for a report document."

So, a report document requires doing things by code????? Gee, all report documents?

All kidding aside, what does the following mean?

"If some bookmarks happen to be empty, then i'm running into trouble as it tries to look for bookmarks that do not exist already."

You should NOT be having any of these issues. And with some clear explanations of what you want to do, I am pretty sure we can point you in a direction that will work.

For one thing, WHY on earth would the userform be looking for bookmarks that do not exist??

fumei
04-28-2008, 03:53 AM
BTW: get past the image in a DOCVARIABLE thing. You can not put an image file in a document variable.

There are things like INCLUDEPICTURE, which will...ummmm....include a picture.

Steve, your link to the multiple-bookmarks-then-delete thread is incorrect. It is the same link as the multi-line. I should have that myself, since it does come up somewhat regularly. I have been depending on you to refer people.

<slaps knee>

lucas
04-28-2008, 07:41 AM
Steve, your link to the multiple-bookmarks-then-delete thread is incorrect. It is the same link as the multi-line. I should have that myself, since it does come up somewhat regularly. I have been depending on you to refer people.

<slaps knee>

I thought I was doing so well......darn. Link corrected in post #5