Excelnewbie11
New Member
- Joined
- Sep 26, 2013
- Messages
- 6
I have the below macro written and attached to a button in word.
The purpose of the macro is to essentially add a front cover to any word document. This front cover (made in another word document) is inserted and takes up all of page 1, there are editable fields on this front cover
You may be able to see what I’m trying to do (I’m really new to VBA) but essential what I’m trying to achieve:
Clear formatting on page 1
Delete header and footer information (page 1 only)
Set the margins so that when the file is inserted it sits in the correct place
Insert document
Page break
Keep all original formatting for the rest of the text. i.e normal margins, header and footer data, orginal fonts, text sizes ect
Currently this inserts ok, where I want it to, however sometimes the front cover that is inserted, changes format, line spacing mainly. I cant work out why. Also the font and colour of text in the inserted file affects the original document text
Also when I press the macro button in a blank word document, the inserted file overruns the first page, however it doesn’t go onto the next page it just disappears. Why does it act different in a blank document?
Please could you look at what I have done and make some suggestions please? Again im really new to this so the below is probably utter rubbish!!
Thanks in advance
Matt
Sub AddProfileSheet()
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0.63)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.PageSetup.LeftMargin = CentimetersToPoints(1.2)
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.PageSetup.RightMargin = CentimetersToPoints(1.2)
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.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ChangeFileOpenDirectory "\\*********\"
Selection.InsertFile FileName:="Cover Sheet.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub
The purpose of the macro is to essentially add a front cover to any word document. This front cover (made in another word document) is inserted and takes up all of page 1, there are editable fields on this front cover
You may be able to see what I’m trying to do (I’m really new to VBA) but essential what I’m trying to achieve:
Clear formatting on page 1
Delete header and footer information (page 1 only)
Set the margins so that when the file is inserted it sits in the correct place
Insert document
Page break
Keep all original formatting for the rest of the text. i.e normal margins, header and footer data, orginal fonts, text sizes ect
Currently this inserts ok, where I want it to, however sometimes the front cover that is inserted, changes format, line spacing mainly. I cant work out why. Also the font and colour of text in the inserted file affects the original document text
Also when I press the macro button in a blank word document, the inserted file overruns the first page, however it doesn’t go onto the next page it just disappears. Why does it act different in a blank document?
Please could you look at what I have done and make some suggestions please? Again im really new to this so the below is probably utter rubbish!!
Thanks in advance
Matt
Sub AddProfileSheet()
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0.63)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.PageSetup.LeftMargin = CentimetersToPoints(1.2)
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.PageSetup.RightMargin = CentimetersToPoints(1.2)
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.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ChangeFileOpenDirectory "\\*********\"
Selection.InsertFile FileName:="Cover Sheet.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub