VBA Word If Then Else Problem

Reply

Join Date: Aug 2009
Posts: 1
Reputation: dfroach is an unknown quantity at this point 
Solved Threads: 0
dfroach dfroach is offline Offline
Newbie Poster

VBA Word If Then Else Problem

 
0
  #1
Aug 5th, 2009
Hi,
Am having a problem with what seems like a simple issue. I am trying to sort short section of a document but am having trouble selecting the text for the sort. It's a TV guide. Trying to sort the channel numbers.

Typical sections look like:

19:00
5-1 Inside Edition
9-1 Entertainment Tonight
7-1 Access Hollywood
19:30
5-1 Chronicle
9-1 Chronicle
7-1 Extra
20:00


Code that fails follows. The If statement always goes to Else. The MsgBox content is correct for the current selected paragraph. Such a simple thing and I'm lost. Please keep it as simple as possible.

With Selection.Find
.Text = "^t[0-9]{1,2}-[0-9]^t*^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
MsgBox Selection.Text
'
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
Selection.GoTo What:=wdGoToBookmark, Name:="\para"
Msgbox Selection.Text
'
If Selection.Text = "^t[0-9]{1,2}-[0-9]^t*^13" Then
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
Selection.GoTo What:=wdGoToBookmark, Name:="\para"
'
Else: Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdMove
Selection.GoTo What:=wdGoToBookmark, Name:="\para"
End If
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC