inserting a file to act as a front cover sheet on page 1

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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top