Solution to type word.application is undefined

g000we

Member
Joined
Mar 22, 2007
Messages
8
Programming Experience
1-3
type word.application is undefined
type word.mailmerge is undefined
etc.

I got these errors.

I found adding..

(at the top, above procedures)

VB.NET:
''UNKNOWN IF NECESSARY 
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.InteropServices[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] Microsoft.Office.Interop.Word[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.windows[/SIZE]

..Then expand the objects with full referencing..

VB.NET:
[SIZE=2][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] theMailMergeVariable [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Microsoft.Office.Interop.Word.MailMerge[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] theMailMergeFieldsVariable [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Microsoft.Office.Interop.Word.MailMergeFields[/SIZE]
 
''..etc..
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] g [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.ListViewGroup[/SIZE]
 
 
[/SIZE]


etc.. To the others!

Now works! So I'm happy! :)
If anyone else has a better idea on the solution then post it!
 
Last edited:
You use imports to avoid having to qualify the types fully each variable.

I also found there is difference between the earlier used object library namespace 'Word' and newer Primary Interop Assembly namespace 'Microsoft.Office.Interop.Word', most older code examples use the former for example 'Word.Application'. What you can do if it feels easier to work with the 'Word' namespace is to declare and name the import like this:
VB.NET:
[SIZE=2][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] Word = Microsoft.Office.Interop.Word[/SIZE][/SIZE]
 
I probably should mention that I did add lots of library references to the project. i.e. Word 11.0 .COM object, Office 11.0 COM object, Word.NET object, etc. Whether they've had an effect on it.. I'm clueless!
 
Back
Top