PDA

View Full Version : Solved: Not able to run two codes at once



pradeepdeepu
01-13-2013, 08:42 PM
Hi,

I have two codes in on module, Test1 () and Test2 (), and i have a script to run both these codes as RunAll () and assigned a keyboard shortcut. (Cntrl+Num0).

When i execute RunAll (), only Test 1 code is executing not Test2.

Code:

Sub Test1()
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim wrdRef As Object
sCheckDoc = "C:\Users\pradeep\Desktop\Word List.docx"
Set docCurrent = Selection.Document
Set docRef = Documents.Open(sCheckDoc)
docCurrent.Activate
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Underline = True
.Replacement.Font.TextColor = wdColorBlue
.Replacement.Font.Italic = True
.Replacement.Text = "^&"
.Forward = True
.Format = True
.MatchWholeWord = True
.MatchCase = True
.MatchWildcards = False
End With
For Each wrdRef In docRef.Words
If Asc(Left(wrdRef, 1)) > 32 Then
With Selection.Find
.Wrap = wdFindContinue
.Text = wrdRef
.Execute Replace:=wdReplaceAll
End With
End If
Next wrdRef
docRef.Close
docCurrent.Activate

End Sub
Sub Test2()
Dim oRng As Word.Range
Dim arrWords
Dim i As Long
arrWords = Array("keep and immaculate", "24-hr")
For i = 0 To UBound(arrWords)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = arrWords(i)
.MatchWholeWord = True
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
Sub RunAll()
'
' RunAll Macro
'
'
Call Test1
Call Test2
End Sub

Can anyone pls help me on this.

Thanks in Advance

fumei
01-14-2013, 03:53 PM
Are you sure Test2 is not executing? Try Stepping through the code.

BTW, there are number of things incorrect with your code. For example: With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Underline = True
.Replacement.Font.TextColor = wdColorBlue
.Replacement.Font.Italic = True
.Replacement.Text = "^&"
.Forward = True
.Format = True
.MatchWholeWord = True
.MatchCase = True
.MatchWildcards = False
End With does nothing, as there is no Execute.

As for Test2, if there is no example of "keep and immaculate", "24-hr", nothing happens. Also...there is no Replacement text.

fumei
01-14-2013, 03:54 PM
Oh, and you marked this as "Solved". Since no one posted anything, I assume this means you solved it yourself. If this is true...SAY SOMETHING!