Insert Graphics to Word Document

Thanks Thanks:  0
Results 1 to 7 of 7

Thread: Insert Graphics to Word Document

  1. #1
    Board Regular
    Join Date
    Feb 2016
    Location
    UK
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Insert Graphics to Word Document

     
    Hi

    I am hoping there is a boffin that can help?

    I tend to do all my VBA in Excel as an accountant, but I have a scenario where I have to do some VBA in Word and I am struggling with which methods to use.

    I have a pre-generated word specification document that I need to insert the corporate graphics (which is sized to A4) to after the specification is generated, I have been playing with shapes and inlineShapes, the main problems are the following:

    1) The graphic file I need to add is a full page graphic that should cover the entire page width/height (100%*100%) (ignoring page margins)
    2) The graphic needs to be added behind the existing text
    3) The graphic will be different depending on page number (1st page master graphic, last 2 pages no graphic & all other pages should be the continuation graphic)
    4) No fixed document length (guessing I will need to cycle through the pages collection and use a case/if statement for this)

    Unfortunately, the graphic can not be broken down into header/footer portions.

    I currently have the following, however this locates the image inside the margins and shrinks the graphic to fit.

    Code:
    ActiveDocument.Shapes.AddPicture _
    FileName:= FilePath, LinkToFile:= False, SaveWithDocument:=True, Left:=0, Top:=0
    I do not know if I am heading in the right direction, so any pointers would be greatly appreciated.
    Regards

    Dave Blake MAAT
    (Member of the Association of Accounting Technicians )

  2. #2
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,537
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert Graphics to Word Document

    If you configure the document with a 'different first page' layout, you can:
    • insert the first graphic into that page's header, formatted the full-page size and 'behind text' there.
    • create a temporary second page (e.g. via Ctrl-Enter) then, in that page's header, insert a field coded as:
    {={NUMPAGES}-{PAGE}-1 \# "'Continuation graphic';;"}
    with your continuation graphic inserted inline where indicated between the pair of single quotes.
    • delete the temporary second page.

    All of this can be done with VBA, too, but it's better to create a suitable template using the above method, then have your code create whatever new documents you need using that template.

    Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required.
    Last edited by Macropod; Jan 9th, 2018 at 07:07 PM.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    Board Regular
    Join Date
    Feb 2016
    Location
    UK
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert Graphics to Word Document

    Hi Paul

    Thank you very much for taking the time to reply to my question it is very much appreciated!

    I have a couple of follow ups

    1) where you state to insert the continuation graphic inline, do you literally the graphic or just the file string as I have done the following, but doesn't appear to be working?

    {={NUMPAGES}-{PAGE}-1 \# "'C:\Users\dave.blake\Documents\SpecGraphics\14018 LHs-4.jpg';;"}



    2) I also need to make the final 2 pages are blank (no continuation graphics), is that possible by tweaking the code provided?

    3) I am also going to need to be able to write a bit of VBA to "Switch These Graphics" as whilst they are email friendly, they are not printer friendly!

    Many Thanks

    Dave
    Regards

    Dave Blake MAAT
    (Member of the Association of Accounting Technicians )

  4. #4
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,537
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert Graphics to Word Document

    Quote Originally Posted by DaveBlakeMAAT View Post
    1) where you state to insert the continuation graphic inline, do you literally the graphic or just the file string as I have done
    You literally you literally the graphic.
    Quote Originally Posted by DaveBlakeMAAT View Post
    2) I also need to make the final 2 pages are blank (no continuation graphics), is that possible by tweaking the code provided?
    That's precisely what the field code does.
    Quote Originally Posted by DaveBlakeMAAT View Post
    3) I am also going to need to be able to write a bit of VBA to "Switch These Graphics" as whilst they are email friendly, they are not printer friendly!
    I don't understand what you mean about not being 'printer friendly'. Properly implemented, you'll have the full-page graphic on the first page and the continuation graphic on all subsequent pages except the last two, regardless of the document length. No VBA is required.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    Board Regular
    Join Date
    Feb 2016
    Location
    UK
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert Graphics to Word Document

    Thanks Paul

    I get it the ;; in the field is referencing the final pages.

    The corporate graphic has an awful lot of colour in it which is fine when sending to the customer as a PDF, however the costs to print would be very high (due to the amount of colour/ink requirements), so we are looking to be able to offer a version that would be cheaper for the customer to print.

    So my thought was that if I set up the default template as you have recommended above, I could then create a macros that could toggle the graphics to lighter shades if the customer requests a printer friendly version.
    Regards

    Dave Blake MAAT
    (Member of the Association of Accounting Technicians )

  6. #6
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,537
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert Graphics to Word Document

    Quote Originally Posted by DaveBlakeMAAT View Post
    I get it the ;; in the field is referencing the final pages.
    Nope. They're numeric picture switch argument separators for -ve and 0 values, respectively.
    Quote Originally Posted by DaveBlakeMAAT View Post
    The corporate graphic has an awful lot of colour in it which is fine when sending to the customer as a PDF, however the costs to print would be very high (due to the amount of colour/ink requirements), so we are looking to be able to offer a version that would be cheaper for the customer to print.

    So my thought was that if I set up the default template as you have recommended above, I could then create a macros that could toggle the graphics to lighter shades if the customer requests a printer friendly version.
    Reducing the colour saturation isn't likely to greatly reduce printing costs. A far greater reduction in printing costs- without touching the colouration - can be achieved by the end-user switching the printer to b/w mode.

    In any event, additional field coding could be used to switch between the colour image and, say, a grey-scale version of it (giving you greater control over the shading). Once you start having recourse to macros, you're at the mercy of whatever macro security settings the recipients use - and whether they allow the macro to run when their security settings don't block it.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  7. #7
    Board Regular
    Join Date
    Feb 2016
    Location
    UK
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert Graphics to Word Document

      
    Thanks Paul

    My boss has made a slight change to the way he wants this to work, which has made life a whole lot simpler!!!

    Your code provided is extremely useful and is going to fulfil my requirements (with a slight modification), so thank you very much for pointing me in the right direction.

    I did have a small issue with the code which was down to me not fully reading your reply correctly, in the fact that I thought the CTRL+F9 was only required for the full field curly braces and that I could manually type the curly braces for the sub-fields. Ctrl+F9 is required for all fields and sub-fields.

    Thanks again for taking the time to assist an accountant venturing into the world of MS Word!!!

    Regards

    Dave
    Regards

    Dave Blake MAAT
    (Member of the Association of Accounting Technicians )

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com