#1
|
|||
|
|||
Complex VBA Code to Resize Alternating Images at the End of a Mail Merge
Hello!
I have been working on this project for work for a couple weeks now and cannot figure out how to write the macro according to the needs of the project. I am using mail merge to create a three different letters with the use of many If-Then-Else statements. There are links to two different images within each letter. The first image is a header that is formatted as the correct size. The second image is stretched to the wrong size and, when the image is toggled, the image is no longer stretched but it is still not the right size. I have tried placing the image merge field in a text box that was the correct size but the image did not fit the box. I have tried to program a macro to resize the selected images but am unable to select every other image in the document. There are nearly 1,000 letters and if I am unable to figure this out I will have to resize every image manually. I have searched far and wide for the answer but have come up empty handed. One thought I had was to program a macro that would resize every other image in a document to a certain height or width, while keeping the aspect ratio. If someone could help me write a macro for this that would be tremendous!! I have attached an image of the mail merge document I am working with, the document it produces, and the ideal look of the document for clarity. The first name of the student has been blacked out for privacy purposes. Sincerely, macropodjr |
#2
|
||||
|
||||
To constrain an image to fit within a given size, create a single-cell table with a fixed height and width to wherever you want the image to go, then insert the field code into that. The inserted images will resize, at the correct aspect ratio for the picture, to fit the space available. No VBA or post-merge processing required.
To create a single-cell table with a fixed height and width, use Insert|Table and choose one cell. Then, for the: • rows, set the exact row height under Table Tools>Layout>Properties>Row>Specify Height>Exactly. • columns, set the preferred column width under Table Tools>Layout>Properties>Columns, and uncheck the 'automatically resize to fit contents' option under Table Tools>Layout>Properties>Table>Options. You might also want to set the cell margins to 0 all round. It's also a good idea to format the table paragraph with 0 before/after spacing.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you for your response.
I have tried multiple times to create a single-cell table with a fixed size. The image does not fit to the size of the text box. The image remains its original size. |
#4
|
||||
|
||||
Cross-posted at: http://www.vbaexpress.com/forum/show...f-a-Mail-Merge
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
||||
|
||||
Unless your images are undersized - which is contrary to what your original post implied - it works if you follow the instructions given.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Quote:
Thank you and my apologies, macropodjr |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Complex Mail Merge based on Criteria | fairchance | Mail Merge | 11 | 08-22-2015 04:32 AM |
Help with VBA to resize images | Yuffster | Word VBA | 2 | 01-30-2015 06:05 AM |
Mail Merge - QR Codes Images Shrinking | LWManson | Mail Merge | 2 | 08-19-2014 07:47 AM |
Help with a complex mail merge | bekz | Mail Merge | 6 | 05-06-2012 07:10 PM |
Inserting images into mail merge | lorraine_hamilton | Mail Merge | 0 | 10-19-2009 09:55 AM |