Word VBA MACRO adding blank pages to start of document

jacinthn

Board Regular
Joined
Jun 15, 2010
Messages
96
I have below macro for coping all open word docs into a "master" sheet and adding a page break then a blank page after each doc copied.
it works fine, however its adding 2 blank pages at the top of the document when it copies, so my first 2 pages on my master are blank.
I am not sure how to get the first document copied to the first page in the master sheet,
so i can stop getting those 2 blank pages on top.

Any ideas?


thanks




Sub DLS()</SPAN>
Dim i As Integer</SPAN>
Dim strKeepOpen As String</SPAN>
strKeepOpen = ("master.docm")</SPAN></SPAN>


For i = Documents.Count To 1 Step -1</SPAN>
If Documents(i).Name <> strKeepOpen Then Documents(i).Activate</SPAN>
Selection.WholeStory</SPAN>
Selection.Copy</SPAN>
If ActiveDocument.Name <> strKeepOpen Then ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges</SPAN>
Windows("master.docm").Activate</SPAN>
Selection.GoTo wdGoToBookmark, , , "\EndOfDoc"</SPAN>
Selection.PasteAndFormat (wdPasteDefault)</SPAN>
With ActiveWindow.View</SPAN>
.ShowRevisionsAndComments = False</SPAN>
.RevisionsView = wdRevisionsViewFinal</SPAN>
End With</SPAN>
Selection.InsertBreak Type:=wdPageBreak</SPAN>
Selection.InsertNewPage</SPAN>



Next i</SPAN>


End Sub</SPAN>
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
If you are starting with a blank master document, this will work:

Code:
' this is a Word macro


Sub DLS()
Dim i%, strKeepOpen$


strKeepOpen = ("master.docm")


For i = Documents.Count To 1 Step -1
    If Documents(i).Name <> strKeepOpen Then Documents(i).Activate
    Selection.WholeStory
    Selection.Copy
    If ActiveDocument.Name <> strKeepOpen Then ActiveDocument.Close SaveChanges:=0
    Windows("master.docm").Activate
    If i = Documents.Count Then
        Selection.GoTo wdGoToBookmark, , , "\StartOfDoc"
    Else
        Selection.GoTo wdGoToBookmark, , , "\EndOfDoc"
    End If
    Selection.PasteAndFormat (wdPasteDefault)
    With ActiveWindow.View
        .ShowRevisionsAndComments = False
        .RevisionsView = wdRevisionsViewFinal
    End With
    Selection.InsertBreak Type:=wdPageBreak
    Selection.InsertNewPage
Next


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,290
Members
449,218
Latest member
Excel Master

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