problem using Select/Selection

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
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?UnlhbiBLYXNzZWw=?=,
Set myRange = WordDoc.Content <== Error 13, Type Mismatch, wtf
Just use WordDoc.Range instead of Content and you should be OK.

Although, if you're not going to actually USE the range object,
no need to declare it...

You should find some articles on automating the .Find
functionality on the word.mvps.org site. The short explanation of
Selection vs. Range is very much like why you'd use a Range in
Excel vs. Selection: the screen doesn't jump around, and you know
exactly what you're working with.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top