J
JinkyJulie via OfficeKB.com
Hi again all...
I have a userform, code is below... I want to make the choice and perform the
typing in the cells... (/70, etc...) along with the text replacement...
The text replacement works brilliantly but the typing into the cells does not
occur... I've played with it, researched and played some more... no good...
It's got to be something simple to give me this much grief...
Any direction would be very appreciated... (note: I know that looping through
the cells would be better... haven't gotten that far yet...)
As always, thanks for your time to help me learn Word VBA...
Regards,
Julie
Private Sub cmdOK_Click()
Dim strFruit As String
Dim i As Integer
If optFruitOne = True Then strFruit = "Banana "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/70"
End If
If optFruitTwo = True Then strFruit = "Apple "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/64"
End If
If optFruitThree = True Then strFruit = "Orange "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/83"
End If
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = strPatrol
.Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute
Application.ScreenUpdating = False
For i = 1 To 8
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Next i
frmPatrolChoice.Hide
Selection.HomeKey Unit:=wdStory
End Sub
I have a userform, code is below... I want to make the choice and perform the
typing in the cells... (/70, etc...) along with the text replacement...
The text replacement works brilliantly but the typing into the cells does not
occur... I've played with it, researched and played some more... no good...
It's got to be something simple to give me this much grief...
Any direction would be very appreciated... (note: I know that looping through
the cells would be better... haven't gotten that far yet...)
As always, thanks for your time to help me learn Word VBA...
Regards,
Julie
Private Sub cmdOK_Click()
Dim strFruit As String
Dim i As Integer
If optFruitOne = True Then strFruit = "Banana "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/70"
End If
If optFruitTwo = True Then strFruit = "Apple "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/64"
End If
If optFruitThree = True Then strFruit = "Orange "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/83"
End If
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = strPatrol
.Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute
Application.ScreenUpdating = False
For i = 1 To 8
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Next i
frmPatrolChoice.Hide
Selection.HomeKey Unit:=wdStory
End Sub