Possible? yes. Reasonable ? Are you willing to devote many hours to the
project or pay for someone else to do so? Would it work to simply create a
new envelope as a separate document?
The reason it gets inserted at the front is that this is a simple way to
insert without messing up page numbering, headers/footers, etc. Also, the
envelope is always then page number 0. People developing for Word assume
that this will be the case.
I use a macro that pulls three-line addresses from a letter and creates an
envelope as a separate document using an envelope template. That macro is
posted below in case it is of use to you. (The envelope template has
macrobutton fields for insertion of address information. The SelectIt sub
makes sure the info goes into the correct place on the new envelope.) I keep
my envelope template in the "Letters & Faxes" folder of the Workgroup
templates folder. The workgroup templates folder is usually a network drive.
Sub LetterEnv()
Dim sName As String
Dim sAddress As String
Dim sCSZ As String
Dim sTemplatesPath As String
On Error GoTo ErrorHandler
'
sTemplatesPath = WorkGroupPath & "Letters & Faxes\"
'
SelectStyle ("Inside Address Name")
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
sName = Selection.Text
SelectStyle ("Inside Address")
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
sAddress = Selection.Text
SelectStyle ("Inside Address")
SelectStyle ("Inside Address")
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
sCSZ = Selection.Text
Selection.Collapse
'
' Create new envelope document and go to place for inserting address
Documents.Add Template:= _
sTemplatesPath & "Kenyon Legal Envelope.dot", _
NewTemplate:=False
SelectIt (2)
'
'
Selection.Text = sName
SelectIt (2)
Selection.Text = sAddress
SelectIt (2)
Selection.Text = sCSZ
SelectIt (2)
Selection.Text = ""
SelectIt (2)
Selection.Text = ""
SelectIt (1)
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, _
Text:="BARCODE \u """ & sCSZ & """", _
PreserveFormatting:=False
GoTo EndOfSub
ErrorHandler:
MsgBox Prompt:="The blue envelope button doesn't work. Try the white
one.", _
Title:="Oops! Sorry"
EndOfSub:
End Sub
This uses a couple of functions.
Function SelectStyle(StyleName As String)
' Finds next instance of style,
' selects first paragraph in style
'
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles(StyleName)
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
.ClearFormatting
End With
End Function
Function WorkGroupPath() As String
' Written by Charles Kenyon
' February 28, 2003
'
' Used by templates menus to set location of templates.
' Returns workgroup tempates path with "\" at the end.
'
' This is needed because if the folder is a network drive rather
' than a folder, it will have the "\" already. If it is a folder,
' it will not have the backslash. This function gives a string
' with the backslash in either case.
'
WorkGroupPath =
Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
If Right(WorkGroupPath, 1) <> "\" Then
WorkGroupPath = WorkGroupPath & "\"
End If
End Function
Sub SelectIt(iField As Integer)
' Routine goes to beginning of document and then goes to field
' iField sets number of field to go to
' Used in new document menus
'
Dim iNumber As Integer
Selection.HomeKey Unit:=wdStory
For iNumber = 1 To iField
Selection.NextField.Select
Next iNumber
End Sub
Hope this is of some help.