Help Generating Word Doc Using Excel VBA

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
I am using Excel 2007. I am attempting to generate a Word Document (using a template) using Excel VBA. I have two problems stumping me:

1. I want to create a userform that gives me the option to remove the footer on the document by clicking a checkbox on/off. I know how to create the userform and checkbox, but how do you remove the footer in the Word document programmatically?

When I recorded a macro in Word 2007, it gave me:
Code:
WordBasic.RemoveFooter

Note: The template I am using doesn't have a footer on the cover page. It only exists on all subsequent pages.

2. I also want the userform to provide the option to add a watermark. Word has several pre-sets which I would like to access, such as Confidential, Draft, Sample, etc. All of the examples I found online show how this can be done via Word VBA, something like this:

Code:
ActiveDocument.AttachedTemplate.BuildingBlockEntries("CONFIDENTIAL 1").Insert Where:=Selection.Range, RichText:=True

How would I get this to work via Excel VBA?

Any ideas experts?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I am using Excel 2007. I am attempting to generate a Word Document (using a template) using Excel VBA. I have two problems stumping me:

1. I want to create a userform that gives me the option to remove the footer on the document by clicking a checkbox on/off. I know how to create the userform and checkbox, but how do you remove the footer in the Word document programmatically?

When I recorded a macro in Word 2007, it gave me:
Code:
WordBasic.RemoveFooter

Note: The template I am using doesn't have a footer on the cover page. It only exists on all subsequent pages.

2. I also want the userform to provide the option to add a watermark. Word has several pre-sets which I would like to access, such as Confidential, Draft, Sample, etc. All of the examples I found online show how this can be done via Word VBA, something like this:

Code:
ActiveDocument.AttachedTemplate.BuildingBlockEntries("CONFIDENTIAL 1").Insert Where:=Selection.Range, RichText:=True

How would I get this to work via Excel VBA?

Any ideas experts?


if in excel you need to add the word referance libaray.

goto the vba editor and the Tools/References and select Microsoft Word object libaray then OK
 
Upvote 0
You need to go section by section through the Word document, and remove each section's footer. Experiment in Word VBA, and concentrate on the Object Browser and IntelliSense instead of the macro recorder, then copy the relevant code with the appropriate references to the Word app. (You don't need the reference to the Word library.)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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