View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Please don't give up on me yet!

The first declarations (As Word.Application) expect to have a referent to
microsoft word.

Open that workbook
go into the VBE
select that project
tools|References
Look for Microsoft Word and check it.

Alternatively, you could just use the "as object" lines and it should work ok.


Curt wrote:

copied code and ran first line Dim WDApp As Word.Application gave error
user defined type not defined Went back and noticed ' in front of Dim put it
back in then 2nd line gave same error. Went back and removed '. I am stumped
as to why this machine of mine will find the file on A but so much problem on
C. I read something about a reference to something by someone any ideas

"Dave Peterson" wrote:

I saved this from a previous post. Maybe it'll help you:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim myPWD As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\doc10.doc"
myPWD = "mypassword"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

WDDoc.WritePassword = myPWD
WDDoc.Close savechanges:=True

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

The purpose of this code was to open a file and give it a password. But there
might be something that you can use.

tbaam wrote:

So I changed the code to this
Sub Open_Wordfile()
Dim Word As Object
Dim MyXL As Object
Set Word = GetObject("C:\Documents and Settings\files\test.doc")
Set MyXL = GetObject(, "Word.application")
MyXL.Application.Visible = True

End Sub

The file does exist but I now receive the following error:
Run-time error 432 "File name or class name not found during automation
operation"

...looked for info on this and found that I need this dll.
regsvr32.exe C:\WINDOWS\SYSTEM\Dao360.dll

I installed it and it said it was correct....

but i still get the error...any ideas

"Dave Peterson" wrote:

Are you sure it's 524 and not 424?

If the error is really 424, it could be because you misspelled WordApp in the
..visible line.

(I don't get 524 when the file doesn't exist (Office 2003).)

tbaam wrote:

I am trying to open a word dopcument from excel...below is the code I am
running but I receive the following error....that is runtime error
524...which indicates that the file does not exit...but it does. I searched
through the other questions and did make sure that the microsoft Word 11.0
object library is available. What am I still doing wrong.

Sub OpenAWordDoc()
Dim WordApp As Object, WorddDoc As Object

Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open "C:\Documents and Settings\files\Test.doc"
WorddApp.Visible = True

End Sub

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson