Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing word from empty space 2

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Im using this to clear my spaces, but i cant get it to work i only get a runtime error. Im doing it while the "userform initializes". So that the paragraphs will be cleaned

With Selection.Find
.Text = "^13{2,}"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With

Dim MyRange As Range
Set MyRange = ActiveDocument.Paragraphs(1).Range
If MyRange.Text = vbCrLf Then MyRange.Delete

Set MyRange = ActiveDocument.Paragraphs.Last.Range
If MyRange.Text = vbCrLf Then MyRange.Delete
 
It says i cannot interpret the text i search?

Does somebody have any hint on this.. I want it to search for paragraphs and delete them.
 
Which runtime error message ?
Which line of code highlighted when in debug mode ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
its in swedish im translating freely so ill do my best this is what it tells med

its runtime error 5560 the text i search contains illegal/invalid patternmatchingexpression or something like that patternmatchingexpression = in swedish mönstermatchningsuttryck if that can be of any help..


debug mode goes like this im pressing f8 to get to the next row..
-->UserForm2.Show
-->Private Sub UserForm_Initialize()
-->stadafrantomt
Sub stadafrantomt()

With Selection.Find
.Text = "^13{2,}"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
-->here it stops!!
End With

 
I'd try this:
.Text = "^13{2[!];[/!]}"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It worked but the funtiocn aint taking away all the empty space, i think i need a way to rest all pagebreaks.. so it can work its magic...

Thanks for the semicolon it worked =)
 
Hi kalle,

If you're trying to delete manual page breaks, search for ^12 and replace with nothing. You may want to execute this before executing your other Find/Replace.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top