View Single Post
 
Old 03-04-2019, 09:37 AM
Banditsv2 Banditsv2 is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Mar 2019
Posts: 1
Banditsv2 is on a distinguished road
Default Select and Cut Certain Pages Containing Certain Strings?

So let me start out by saying I'm extremely new to VBA and creating macros for anything, so I apologize if I don't make any sense of what I'm trying to say.

With that said what I am trying to do is select and copy or cut certain pages out of a word document that contain a set string. I can't seem to figure it out I created a shortcut to select and cut the text but it only does one page even when I use the find all in main document it only select the one that is shown on my screen.

See example .doc below. I'm trying to search for text such as "Trouble Phone Line Fail" such as on pages 2 & 4 and cut those pages out to be able to post into a new document, leaving pages 1 & 3 intact.

Code:
Sub TESTING()
'
' TESTING Macro
'
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "Trouble Phone Line Fail"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Application.Run MacroName:="Normal.NewMacros.SelectPage"
    Selection.Cut
End Sub

AND

Sub SelectPage()
'
' SelectPage Macro
' Select active page and clear text formating
'
ActiveDocument.Bookmarks("\Page").Range.Select
    Options.DefaultHighlightColorIndex = wdNoHighlight
    Selection.Font.Color = wdColorBlack
End Sub
Attached Files
File Type: docx Example.docx (12.7 KB, 12 views)

Last edited by Banditsv2; 03-04-2019 at 09:47 AM. Reason: Accidentally posted before completing post
Reply With Quote