Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2019, 09:37 AM
Banditsv2 Banditsv2 is offline Select and Cut Certain Pages Containing Certain Strings? Windows 7 64bit Select and Cut Certain Pages Containing Certain Strings? Office 2013
Novice
Select and Cut Certain Pages Containing Certain Strings?
 
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, 10 views)

Last edited by Banditsv2; 03-04-2019 at 09:47 AM. Reason: Accidentally posted before completing post
Reply With Quote
  #2  
Old 03-04-2019, 02:22 PM
macropod's Avatar
macropod macropod is offline Select and Cut Certain Pages Containing Certain Strings? Windows 7 64bit Select and Cut Certain Pages Containing Certain Strings? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim DocSrc As Document, DocTgt As Document, Rng As Range
Set DocSrc = ActiveDocument: Set DocTgt = Documents.Add
With DocSrc.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "TROUBLE PHONE LINE FAIL"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWildcards = False
    .Execute
  End With
  Do While .Find.Found
    Set Rng = .Duplicate
    Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    DocTgt.Range.Characters.Last.FormattedText = Rng.FormattedText
    Rng.Text = vbNullString
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select and Cut Certain Pages Containing Certain Strings? Select rows w/cells containing given character strings, then sum cell in two other col. LarryHills Excel 1 02-17-2017 03:55 PM
Select and Cut Certain Pages Containing Certain Strings? How to Dim a substring between two strings dwirony Word VBA 4 10-28-2016 07:51 AM
Select specific pages to print or save Jack Byrindi Word VBA 0 01-16-2014 03:14 PM
Select and Cut Certain Pages Containing Certain Strings? Buttons to select pages greg__reynolds Word 1 08-30-2012 05:20 AM
Select and Cut Certain Pages Containing Certain Strings? update style of all strings available between two specific strings vikrantkale Word 1 03-28-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:51 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft