Problem with Word 12.0 Object Library

R

Robert Crandal

I'm trying to automate Word 2007 using Excel 2007.
Someone told me that I need to add a reference to the
"Word 12.0 Object Library" in my VBA project, but
all I see is the following error message:

"Name conflicts with existing module, project,..."

Does anyone have an idea what might be wrong?

Thank you!
 
O

OssieMac

Hi robert,

I am assuming that you have VBA code in both the Excel workbook and the Word
document. If you look at the project explorer on the left of the VBA editor,
check to see that you have not got 2 project names the same. (One in Excel
and one in Word)

See following link also.

http://support.microsoft.com/default.aspx/kb/213595
 
R

Robert Crandal

I basically only have VBA code in my Excel module which
simply tries to run Word 2007, it's nothing fancy. I
also have the following variable definition:

Dim axWord as Word.Application

I do need the Word 12.0 Object Libarary for the
"Word.Application" definition, right??
 
O

OssieMac

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
 

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