Problems with working with Word Object

S

Suzette

Hi there,

I am trying to utilize Word as an object in code so that I don't have to
have a reference to it. (Issues with me using Word 2003 and others using
2000).

Here is the code up to the point of error.

Dim wd As Object
Dim wdDoc As Object
Dim lngCount As Long
Dim sRange As Variant
Dim strFile As String
Dim strProvider As String
Dim sngRows As Single

'Set wd = New Word.Application
Set wd = CreateObject("Word.Application")

strFile = Dir(frmMain.txtFrom & "*.doc")

Do Until strFile = ""
lngCount = 0
wd.Visible = True
' wd.ScreenUpdating = False
' wd.WindowState = wd.WindowStateMinimize
wd.Documents.Open frmMain.txtFrom & strFile
frmMain.lblInfo = "Counting " & strFile & "...."
frmMain.lblInfo.Refresh
With wd.Selection
.HomeKey wd.wdstory

If I have the last line as above I get the error "Object doesn't support
this property or method"
If I change it to:
.HomeKey wdstory

The error is "variable not defined"

This will occur with all instances of methods for the selection. It reads
the homekey word fine but not the unit.

Any and all suggestions are welcome and appreciated. Even a suggestion as
to where to research for the answer would be great.

Thank you so much

Suzette
 
T

Tony Jollans

You can't use the Word constants if you don't reference the word library.
wdStory has a value of 6, so use ..

..HomeKey 6

I don't know of any particular reference but all the values can be found in
the Object Browser in Word - or by entering, say, "?wdstory" in the
immediate window (again in Word)
 
T

TC

Um, better to /define/ the constants:

const wdStory = 6

Then other people can see what the code is doing.

HTH,
TC
 
S

Suzette

Thanks all. The reason I'm using the CreateObject instead of referencing
the library is because I am have Office 2003. If I reference the 2003
library then the people who are trying to use it with another version of
Office get errors. I don't want to distribute with the library because I am
concerned about issues with the machines that have a different version
installed.

Your suggestions worked!!!

Thank you both
Thank you thank you thank you
 
J

Jonathan West

Suzette said:
Thanks all. The reason I'm using the CreateObject instead of referencing
the library is because I am have Office 2003. If I reference the 2003
library then the people who are trying to use it with another version of
Office get errors. I don't want to distribute with the library because I
am concerned about issues with the machines that have a different version
installed.

Your suggestions worked!!!

If you are developing a program which is going to be used with different
versions of Word, I would strongly recommend that you work with the *oldest*
version of Word that you intend supporting, and then test with newer
versions.

If you work with the oldest version, you can set a reference to the Word &
Office libraries, and they will still work when the application is used with
*newer* versions of Office.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
Top