| | |
|
|
|
Automation Acess to Word |
| message from Bob W on 30 May 2004 |
I am using Access 2000 9.0.6926-SP3 and Word2000 9.0.6926 SP3 with Reference
to Microsoft Word 10.0 Object library running in Windows XP
D:\AC_Probation\Test.doc exists.and opens under word
I wrote the following code in an Access module attempting to open the word
document.
Dim objWord As Word.Application
Set objWord = GetObject("D:\AC_Probation\Test.doc")
objWord.Visible = True
When I run this I get a run time error13 Type mismatch. The same error
occurs whether Word is running or not. Something obvious must be missing
but I am new to Automation and can make no sense of the error message. Any
help appreciated
|
| david epsom dot com dot au replied to Bob W on 31 May 2004 |
You have returned a Document object, not an Application object.
Declare a document object, or get an application object, or
do like I do: use late bound objects, and declare everything
as 'object'
(david)
"Bob W" <mwund at kcbx . net> wrote in message
news:40baa053$1_1@corp.newsgroups.com...
|
| Bob W replied to david epsom dot com dot au on 31 May 2004 |
I am not sure of the distinction. Could you write the sample code for this
example? - Bob
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
|
| david epsom dot com dot au replied to Bob W on 1 Jun 2004 |
The advantage of late bound objects, as demonstrated by Arvin Meyer,
is that no reference is required, and your other code, including
your start-up and shut-down code, will still work OK even if Word
is not installed. This is not the case with early bound objects.
The disadvantage is that you don't get the help and auto-completion
from the referenced object. Your code used a small mixture: using
GetObject (late bound) instead of New meant that you did not see
the Type Mismatch until runtime.
One option is to write and test as much as possible of your code
using a library reference and early binding, then go through and
change all to generic 'object' references and late binding before
distribution.
Obviously, this is of negligible advantage if you only deploy to
one desktop (your own), but it's good if you plan to widely distribute.
(david)
"Bob W" <mwund at kcbx . net> wrote in message
news:40bb59cf_6@corp.newsgroups.com...
|
| Arvin Meyer replied to Bob W on 31 May 2004 |
Here is an example of some early and late binding with Excel. Remember, with
early binding, you must set a reference. That isn't necessary with late
binding. In the early binding, I am calling the Excel 360() function from
Access.
Early:
Function XL360(Arg1, Arg2) As Double
Dim objXL As New Excel.Application
XL360 = objXL.WorksheetFunction.Days360(Arg1, Arg2)
Set objXL = Nothing
End Function
Late:
Sub TestXL()
Dim objXL As Object
Dim objActiveWkb As Object
Set objXL = GetObject(, "Excel.Application")
objXL.Application.Workbooks.Add
Set objActiveWkb = objXL.Application.ActiveWorkbook
With objActiveWkb
.Worksheets(1).Cells(1, 1) = "Hello World"
End With
objXL.Visible = True
Set objXL = Nothing
Set objActiveWkb = Nothing
End Sub
|
| Tom Wickerath replied to Bob W on 30 May 2004 |
Hi Bob,
Try this subroutine.
Tom
Sub Test()
Dim objWord As Word.Application
Dim doc As Word.Document
'set objWord to current Word instance or create new one
On Error Resume Next
Set objWord = GetObject(, "Word.application")
If Err = 429 Then
Set objWord = New Word.Application
End If
On Error GoTo ProcError
Set doc = objWord.Documents.Open("D:\AC_Probation\Test.doc")
objWord.Visible = True
ExitProc:
' Cleanup
On Error Resume Next
Set doc = Nothing
Set objWord = Nothing
Exit Sub
ProcError:
MsgBox Err & Err.Description
Resume ExitProc
End Sub
_________________________________________
"Bob W" <mwund at kcbx . net> wrote in message news:40baa053$1_1@corp.newsgroups.com...
I am using Access 2000 9.0.6926-SP3 and Word2000 9.0.6926 SP3 with Reference
to Microsoft Word 10.0 Object library running in Windows XP
D:\AC_Probation\Test.doc exists.and opens under word
I wrote the following code in an Access module attempting to open the word
document.
Dim objWord As Word.Application
Set objWord = GetObject("D:\AC_Probation\Test.doc")
objWord.Visible = True
When I run this I get a run time error13 Type mismatch. The same error
occurs whether Word is running or not. Something obvious must be missing
but I am new to Automation and can make no sense of the error message. Any
help appreciated
|
| Bob W replied to Tom Wickerath on 31 May 2004 |
news:40baa053$1_1@corp.newsgroups.com...
|
| Bob W replied to Tom Wickerath on 31 May 2004 |
I tried the code and got an error msg "-2147417851 Automation Error the
server threw an exception" any ideas what it is trying to tell me- Bob
news:40baa053$1_1@corp.newsgroups.com...
|
| Bob W replied to Tom Wickerath on 31 May 2004 |
I tried your code and got an error msg. "-2147417851 Automation Error The
server threw an exception" Any ideas as the error msg, gives me no hint- Bob
news:40baa053$1_1@corp.newsgroups.com...
|
| Tom Wickerath replied to Bob W on 31 May 2004 |
Hi Bob,
Check to make sure that you don't have any missing references. Missing references can cause
strange errors.
http://members.rogers.com/douglas.j.steele/AccessReferenceErrors.html
http://members.iinet.net.au/~allenbrowne/ser-38.html
I tested the code on my PC before sending it, and it worked fine.
Tom
_________________________________________
"Bob W" <mwund at kcbx . net> wrote in message news:40bbd6c1_4@corp.newsgroups.com...
I tried your code and got an error msg. "-2147417851 Automation Error The
server threw an exception" Any ideas as the error msg, gives me no hint- Bob
_________________________________________
"Tom Wickerath" <AOS168RemoveThisSpamBlock@comcast.net> wrote in message
news:bYOdndGcCudWNifdRVn-sA@comcast.com...
Hi Bob,
Try this subroutine.
Tom
Sub Test()
Dim objWord As Word.Application
Dim doc As Word.Document
'set objWord to current Word instance or create new one
On Error Resume Next
Set objWord = GetObject(, "Word.application")
If Err = 429 Then
Set objWord = New Word.Application
End If
On Error GoTo ProcError
Set doc = objWord.Documents.Open("D:\AC_Probation\Test.doc")
objWord.Visible = True
ExitProc:
' Cleanup
On Error Resume Next
Set doc = Nothing
Set objWord = Nothing
Exit Sub
ProcError:
MsgBox Err & Err.Description
Resume ExitProc
End Sub
_________________________________________
"Bob W" <mwund at kcbx . net> wrote in message news:40baa053$1_1@corp.newsgroups.com...
I am using Access 2000 9.0.6926-SP3 and Word2000 9.0.6926 SP3 with Reference
to Microsoft Word 10.0 Object library running in Windows XP
D:\AC_Probation\Test.doc exists.and opens under word
I wrote the following code in an Access module attempting to open the word
document.
Dim objWord As Word.Application
Set objWord = GetObject("D:\AC_Probation\Test.doc")
objWord.Visible = True
When I run this I get a run time error13 Type mismatch. The same error
occurs whether Word is running or not. Something obvious must be missing
but I am new to Automation and can make no sense of the error message. Any
help appreciated
|
|
Archived message: Automation Acess to Word (MS Access Error Message)