C
Christine
I am finding that where a macro is located changes the results of
running the macro. I am currently trying to create a stand alone Word
document with a few simple controls that will generate another Word
document with certain information and a header/footer. I am finding
out that if I put a SetupHdrFtr routine in the ThisDocument module
then it will not work properly, but if it is in a module in Normal
then it works fine. For example, the following routine creates a new
document and puts a header/footer in it and one line of text in the
body of the document. At least that's what happens if the routine is
in a vba module in Normal. But it does not work in the ThisDocument
vba module of my Conrol.doc.
Does anyone have any idea how to make it work in ThisDocument vba
module of my Control.doc? I really want to keep it simple for the
customer who will use it and not have them need to be messing with
placing any extraneous macro documents anyplace else. I want to be
able to just email them a single Word doc and have them be able to use
it right off the bat.
Any ideas would be much appreciated. Thanks, Christine
Sub NewFileWithHdrFtr()
Documents.Add DocumentType:=wdNewBlankDocument
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="this is the text for the header"
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.TypeText Text:=vbTab & vbTab
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.TypeText "this should be in body"
End Sub
running the macro. I am currently trying to create a stand alone Word
document with a few simple controls that will generate another Word
document with certain information and a header/footer. I am finding
out that if I put a SetupHdrFtr routine in the ThisDocument module
then it will not work properly, but if it is in a module in Normal
then it works fine. For example, the following routine creates a new
document and puts a header/footer in it and one line of text in the
body of the document. At least that's what happens if the routine is
in a vba module in Normal. But it does not work in the ThisDocument
vba module of my Conrol.doc.
Does anyone have any idea how to make it work in ThisDocument vba
module of my Control.doc? I really want to keep it simple for the
customer who will use it and not have them need to be messing with
placing any extraneous macro documents anyplace else. I want to be
able to just email them a single Word doc and have them be able to use
it right off the bat.
Any ideas would be much appreciated. Thanks, Christine
Sub NewFileWithHdrFtr()
Documents.Add DocumentType:=wdNewBlankDocument
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="this is the text for the header"
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.TypeText Text:=vbTab & vbTab
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.TypeText "this should be in body"
End Sub