Word Macro for find all / select entire page / cut to new document

Dimmthewitted

New Member
Joined
Aug 31, 2012
Messages
1
Hello,

I am working on a VB script to scan a large document of company statements for certain criteria and then pull each page out and paste it in a new document. I am not a VB coder and got in a bit over my head with deadlines looming.

Right now the code copies and pastes a page into a new document, but not the search page just the current page. Any advice would be greatly appreciated.

Sub RemoveMultiPageStatements()


' create another doc to copy to / label docs

Dim docA As Document
Set docA = ActiveDocument
Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
ActiveDocument.SaveAs2 FileName:= _
"DocB.docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=14
Dim docB As Document
Set docB = ActiveDocument
docA.Activate

Dim SearchTerm As String
SearchTerm = "Page 1 of 2"


' \page selects the entire page


Selection.GoTo What:=wdGoToBookmark, Name:="\page"
Selection.Find.ClearFormatting
With Selection.Find
.Text = SearchTerm
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found Then
Selection.GoTo What:=wdGoToBookmark, Name:="\page"
Selection.Cut
docB.Activate
Selection.Paste
docA.Activate

'remove page 2
Selection.GoTo What:=wdGoToBookmark, Name:="\page"
Selection.Cut
docB.Activate
Selection.Paste
docA.Activate


End If





End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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