Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2012, 05:21 AM
tinfanide tinfanide is offline Word VBA: Continuous Find??? Windows 7 64bit Word VBA: Continuous Find??? Office 2010 32bit
Expert
Word VBA: Continuous Find???
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Word VBA: Continuous Find???


FindTillDocumentEnd.docx

I wonder how I can continuously find the manual line break after the strings "ordered by ministers."
I used "^013" but failed to find it.

And another problem is:
How can I use
Code:
ActiveDocument.Content.Find
to continuously find strings
like what we do in Find And Replace?
Reply With Quote
  #2  
Old 04-22-2012, 03:50 PM
macropod's Avatar
macropod macropod is offline Word VBA: Continuous Find??? Windows 7 64bit Word VBA: Continuous Find??? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Hi tinfanide,

It's not entirely clear what you're after. If you're trying to delete the empty paragraph following "ordered by ministers.", you could use a macro like the following.

This macro deletes all tabs, leading & trailing spaces, linefeeds and empty paragraphs (including those with spaces only) from all cells in all tables (including nested tables) in the active document, without otherwise affecting the formatting of text in the cells.
Code:
Sub TableCleaner()
Application.ScreenUpdating = False
Dim Tbl As Table, Cel As Cell, Rng As Range, Para As Paragraph
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = True
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Text = "[^t]"
      .Replacement.Text = " "
      .Execute Replace:=wdReplaceAll
      .Text = "[ ]{2,}"
      .Replacement.Text = " "
      .Execute Replace:=wdReplaceAll
      .Text = "[^l^13]{1,}"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
      .Text = "[^13 ]{2,}"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
    End With
    For Each Cel In Tbl.Range.Cells
      Set Rng = Cel.Range
      Rng.End = Rng.End - 1
      If Rng.Start <> Rng.End Then
        For Each Para In Rng.Paragraphs
          With Para.Range
            If .Characters.Count = 1 And .Cells.Count = 1 Then
              .Characters.First = vbNullString
              On Error Resume Next
              If .End = .Cells(1).Range.End Then .Characters.Last.Previous.Delete
            End If
            If .End = Rng.End Then Rng.Characters.Last = vbNullString
          End With
        Next
      End If
    Next
  Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-27-2012, 09:13 AM
tinfanide tinfanide is offline Word VBA: Continuous Find??? Windows 7 64bit Word VBA: Continuous Find??? Office 2010 32bit
Expert
Word VBA: Continuous Find???
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Learnt a lot from your example,
especially the use of Range.End and vbNullString
Thank you.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA: Continuous Find??? Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Need continuous audio alert... oooiooo Outlook 1 07-27-2011 10:52 AM
Word VBA: Continuous Find??? Continuous Loop cksm4 Word 6 01-06-2011 09:03 PM
How do you imbed a continuous play mp3 into a ppt Joe Damore PowerPoint 2 09-15-2010 11:13 PM
continuous sound boutells PowerPoint 2 11-27-2009 12:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:28 AM.


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