Consulting

Results 1 to 8 of 8

Thread: try to insert picture with docvariable

  1. #1

    try to insert picture with docvariable

    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

  2. #2
    You cannot add the picture to the variable. You can store the path and use it later:

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

    [/VBA]

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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?

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

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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??

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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>

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by fumei
    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •