| | |
VBA Word If Then Else Problem
![]() |
•
•
Join Date: Aug 2009
Posts: 1
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Help with VBA Word Bookmarks (Windows NT / 2000 / XP)
- Export/Import problem in VBA Word (Visual Basic 4 / 5 / 6)
- Problem in String Search:Please Help (C)
- Error Message in Word: Visual Basic Box 'Macros in this project are Disabled' (Windows NT / 2000 / XP)
- Need To Print PDF using VBA in Word (Visual Basic 4 / 5 / 6)
- Problem with working with math in C (C)
- I need help using VBA for Word Macros (Windows NT / 2000 / XP)
- PLEASE, I need help with this....why can't I get it to work? (Visual Basic 4 / 5 / 6)
Other Threads in the Windows Software Forum
- Previous Thread: Microsoft Word abnormal termination
- Next Thread: Help Please!!!
| Thread Tools | Search this Thread |
acquisition agile albany applications apps asp backup bailout ballmer beta bid billgates binary blackberry boot bostock browser budapest business cisco codeplex codeweavers development documents download ebay economicgrowth economy email ergonomics eu excel exchange facebook freesoftware gadgets gaming google gta halo halowars hyper-v ibm ie8 intel internet java jerryseinfeld jerryyang jobs law licensing linux mac merger microsoft microsoftoffice mobile net news nintendo office officefileformats officesuites openoffice openoffice.org opensource opensuse os outlook patent poi print record redhat researchinmotion rim security server siliconvalley software sony survey takeover timewardenltd. virtualization vista vmware web wii windows windows7 windowslive work xbox xbox360 yahoo yahoo! yang zoho





