Insert Graphics to Word Document

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
190
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.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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:
Upvote 0
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
 
Upvote 0
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.
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.
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.
 
Upvote 0
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.
 
Upvote 0
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.
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top