The macro is supposed to open a new document, put in the fold lines (the line shapes in the macro), enter our return address in column 1, row 2, and then paste as unformatted text the contents of the clipboard in column 1, row 4. Everything needs to be formatted precisely so that the addresses can be seen through the envelope windows.
This is precisely, exactly, the reason for using a template. This is what templates are
for.
Doing it via code each time is NOT the way to go. Here is the
entire code in a template that will do exactly as you have described.
Assumptions:
The template has the fold lines, and table already in it. This is, again, the whole point of templates.
The template is named yadda.dot.
Code:
[b][COLOR=red]' in Normal.dot or other global template[/b][/color red]
Sub Address_Stuff()
' keyboard shortcut = Alt-A
Documents.Add Template:="Yadda.dot"
End Sub
[b][COLOR=red]' in the template Thisdocument code module[/b][/color red]
' again this is the ENTIRE code to do your task
Option Explicit
Const OurAddress As String = "1234 Whatever St." & _
vbCrLf & "SomeCity, Blah"
Private Sub Document_New()
Dim r As Range
ActiveDocument.Tables(1).Cell(2, 1).Range.Text = OurAddress
Set r = ActiveDocument.Tables(1).Cell(4, 1).Range
r.Paste
End Sub
I set up the calling procedure (Address_Stuff) to have a keyboard shortcut. So I can select something in ANY document, click the Copy button, and then hit Alt-A.
What happens.
1. a new document is created, cloned from the template "yadda.dot". Remember this already has your folds and your table.
Code:
Documents.Add Template:="Yadda.dot"
2. when a template is cloned to new document, the Document_New event is fired. This first inserts the CONSTANT OurAddress (already defined) into Cell(1,2).
Code:
ActiveDocument.Tables(1).Cell(2, 1).Range.Text = OurAddress
3. it then pastes whatever you copied into the clipboard into Cell(1,4)
Code:
Set r = ActiveDocument.Tables(1).Cell(4, 1).Range
r.Paste
Done. As it is a new document, your template is unchanged, ready to be used again.
In the above I used a procedure in Normal.dot to start things. But you don;t have to do this. You could have a icon on a toolbar, a menu item (version issues in mind); or simply use File > New and select the template.
Either way, the template is cloned and Document_New fires aand does its thing.
Gerry
Och ammmmm, I think I need a shave.
- hirsute Scot, trying to decide