R
Ryan Kassel
I have a vba function (written in Excel VB 6 Editor) that takes a MS Word Doc
obj and is supposed to return a string. The algorithm is: search "$" from
the end of the document. Return the next decimal number after the found "$".
Function FindMyTotal(WordDoc As Word.Document) As String
Dim myRange As Range
Set myRange = WordDoc.Content <== Error 13, Type Mismatch, wtf
With Selection.Find
.ClearFormatting
.Execute FindText:="$", Forward:=False
If .Found = True Then
.Parent.Expand Unit:=wdWord
.Parent.Copy
Else
TotalFind = ""
Exit Function
End If
FindMyTotal = .Text
End With
End Function
I have important global stuff like:
Dim WordApp As New Word.Application
Dim wdDoc As Word.Document
and everything is working relatively well.
The problem is that I am doing something fundamentally wrong with the
selection/range objects (never used them before) and I could use some
assistance. Thank you so much!
One interesting note is that I can access "WordDoc.Content", in the watch
list, but it reports "Range/Object" type, instead of "Range" type for the
myRange local variable. What's the diff, I wunder?
- Ryan
obj and is supposed to return a string. The algorithm is: search "$" from
the end of the document. Return the next decimal number after the found "$".
Function FindMyTotal(WordDoc As Word.Document) As String
Dim myRange As Range
Set myRange = WordDoc.Content <== Error 13, Type Mismatch, wtf
With Selection.Find
.ClearFormatting
.Execute FindText:="$", Forward:=False
If .Found = True Then
.Parent.Expand Unit:=wdWord
.Parent.Copy
Else
TotalFind = ""
Exit Function
End If
FindMyTotal = .Text
End With
End Function
I have important global stuff like:
Dim WordApp As New Word.Application
Dim wdDoc As Word.Document
and everything is working relatively well.
The problem is that I am doing something fundamentally wrong with the
selection/range objects (never used them before) and I could use some
assistance. Thank you so much!
One interesting note is that I can access "WordDoc.Content", in the watch
list, but it reports "Range/Object" type, instead of "Range" type for the
myRange local variable. What's the diff, I wunder?
- Ryan