#1
|
|||
|
|||
Macro for word to add page break and specific text to end of document
I am looking to create a macro that can be used to add specific text to the end of several documents contained in a specific folder and the subfolders.
At the current end of the document I would like a page break and then specific text added. I was thinking it may be easier to paste the text from the clipboard so that formatting can be maintained. However if it is easier the text can be specified in the macro. Thank yo |
#2
|
||||
|
||||
The Word add-in at http://www.gmayor.com/document_batch_processes.htm will handle the backroom tasks relating to the folders and sub folder processing and it is then a relatively simple process to create a custom function to run from the add-in to insert a specific text at the end, either from the clipboard, or from text saved as an autotext entry or directly from text defined in the function e.g. Using an Autotext entry
Function AddAPage(oDoc As Document) As Boolean Dim oRng As Range On Error GoTo Err_Handler Set oRng = oDoc.Range oRng.Collapse 0 oRng.InsertBreak wdPageBreak Set oRng = oDoc.Range oRng.Collapse 0 Application.Templates("Normal.dotm"). _ BuildingBlockEntries("AutoTextName").Insert _ Where:=oRng, _ RichText:=True AddAPage = True lbl_Exit: Exit Function Err_Handler: AddAPage = False Resume lbl_Exit End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
I am not familiar with the AutoTextName function. I am new to the use of VBA.
If I wanted to insert text that says what is below what would I need to do. Changes: __________________________________________________ ______ Blah Blah Balh |
#4
|
|||
|
|||
Code:
Function AddAPage(oDoc As Document) As Boolean Dim oRng As Range On Error GoTo Err_Handler Set oRng = oDoc.Range oRng.Collapse 0 oRng.InsertBreak wdPageBreak Set oRng = oDoc.Range oRng.Collapse 0 oRng.Text = "Changes: " & vbCr _ & "_________________________________________________________________" & vbCr _ & "Blah, blah, blah." AddAPage = True lbl_Exit: Exit Function Err_Handler: AddAPage = False Resume lbl_Exit End Function |
#5
|
||||
|
||||
Quote:
Or as the text appears short, you could use Greg's suggestion to insert it directly.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#6
|
|||
|
|||
Thank you, sorry for being dumb, but I how do get it in the normal template.
|
#7
|
||||
|
||||
When you press ALT+F3 to save the autotext entry, by default Word 2007 wants to put the entry in the QuickParts gallery of Building Blocks.dotx
Click the dropdown adjacent to Gallery and select Autotext and similarly click the dropdown agains Save In and select Normal.dotm. Then OK. Depending on whether you have Word configured to automatically save the normal template on Close, you may get a prompt to save the template when you close Word. That autotext entry will remain unless Word is closed without saving the template.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to insert multiple pictures to word to a specific size and text wrap | mescaL | Word VBA | 3 | 11-03-2014 10:51 PM |
Page Break based on specific work | mbesspiata | Word | 6 | 01-22-2014 12:40 PM |
Add Page Break to Document | expatchic | Word VBA | 5 | 08-08-2012 04:16 PM |
Deleteing specific text in word document | ubns | Word | 1 | 05-31-2012 10:38 PM |
WORD Macro - import picture - resize - position - page break - loop | Nano07 | Word VBA | 2 | 11-02-2011 05:14 AM |