Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-07-2011, 12:11 PM
needhelp2 needhelp2 is offline VBA help Windows XP VBA help Office 2007
Novice
VBA help
 
Join Date: Jul 2011
Posts: 2
needhelp2 is on a distinguished road
Thumbs down VBA help


Hi guys,

I need to know how i can hit enter by using VBA after a specific word.
Kindly please confirm .I had record below script but unabel to get my result what i need.

I need to insert enter mean all record after </br> move to next time by using enter.

Br,
Smith.

Code:
Sub Macro1()
'
' Macro1 Macro
'
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "<br/>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "<br/>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "<br/>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
End Sub
Reply With Quote
  #2  
Old 07-07-2011, 11:19 PM
macropod's Avatar
macropod macropod is online now VBA help Windows 7 64bit VBA help 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

Hi needhelp,

If you study the Find/Replace options available through Word's user interface, you'll find that you can include the find text as part of the replacement text (ie Replace = ^&) , which can include a paragraph break (ie ^p). So, you can achieve what it appears you're after, using Find/Replace (ie without a macro), where:
Find = <br/>
Replace = ^&^p

The following revision to your macro achieves the same thing:
Code:
Sub Demo()
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "<br/>"
  .Replacement.Text = "^&^p"
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-08-2011, 12:41 AM
needhelp2 needhelp2 is offline VBA help Windows XP VBA help Office 2007
Novice
VBA help
 
Join Date: Jul 2011
Posts: 2
needhelp2 is on a distinguished road
Default

Thanks buddy ,Thank you very very much
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 03:30 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