Hi again Robert,
I would suggest that there is a conflict with some object somewhere. If you
Google the error message you will find some other reasons for the error and
you might be able to identify the problem. However, you don't have to set the
reference if you use late binding like the following. You just don't get the
excel intellisense help with the late binding method and if you want to use
any of the Word constants then you need to find out their value and set them
to the value as a constant in the code.
My suggestion is that you develop the code as a stand alone with a new excel
workbook using early binding and when you have the code you can copy it to
your project and use late binding. After copying code to your project, ensure
you have Option Explicit at the top of the VBA editor page and use
Debug->Compile. If you have any word constants then it will tell you Variable
not defined. Go back to the standalone development and create a small sub
like the following and find the value of the variable and then in the project
either replace the variable with the value or assign the value to the
variable.
Sub TestConstantValue()
MsgBox wdDoNotSaveChanges
End Sub
Example to open Word from Excel.
Sub OpenWord()
'Late binding method
Dim objWord As Object
'Try GetObject first in case
'Word Application is already open.
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err <> 0 Then
'GetObject returns error if not already
'open so use CreateObject
On Error GoTo 0 'Reset error trapping
Set objWord = CreateObject("Word.Application")
End If
With objWord
'Create a new Word document
.Visible = True 'Can be false
.Documents.Add 'Template:=strPathFileName
'If using a template other than default
'assign full path and filename of template
'to variable strPathFileName
'.Documents.Add 'Template:=strPathFileName
End With
'Clean up
Set objWord = Nothing
End Sub