Creating Word 2003 Macro for Variable Documents

smiley3141

Board Regular
Joined
Aug 13, 2010
Messages
77
I am trying to create a macro that will fill out documents in Word 2003 (or Word 2007). I can do this for static documents, but am having trouble with variable documents.

What I mean by this is, my comprehensive template has 61 sections, but for any one case, only 20-30 of them are necessary, and these vary greatly from one time to the next. Also, depending on the particulars, the order in which the sections are printed might change. I have figured out the logic to get everything to print in the correct order, but where can I find help on translating that into VBA?

Also, each section title contains an ordinal ("First", "Seventh", "Thirty-First", etc.) while each section contains paragraphs numbered something like ("7.1.2."). Is there some way to create a Macro in Word that will automatically number the sections and paragraphs correctly? Right now I am thinking of creating a v-lookup table in Excel and having the Word Macro reference this Table to figure out what the next Ordinal, or Paragraph number is. Does this sound like a good way to proceed, or is there a simpler (more direct) way in Word?

I appreciate any help, or references anyone can give me to help me solve this problem.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Smiley,

If your 'template' is a true Word template (.dot, dotx or dotm extension), with properly managed Styles, Section breaks and numbering, then customising documents created from it is a matter of deleting the unwanted Sections and re-arranging the rest. A macro could certainly be created to help with the deletions; the re-arrangements are trickier but could also be done.

Alternatively, if your 'template' is merely a true Word document (.doc, docx or docm extension), you might find it easier to simply bookmark each Section and then, instead of using this document as your template, create another one that uses INCLUDETEXT fields to link to import the bookmarked ranges. That way, you can easily select a whole Section in the target document by selecting the corresponding INCLUDETEXT field. Form there it's a simple matter to delete or re-arrange the Sections, especially if you toggle the field code display on, via Alt-F9 so that you only see the INCLUDETEXT field codes.
 
Upvote 0
Thank you Macropod.

I have not yet checked whether that works, but it is a place to start.

Thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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