CreateObject(“Word.Application”) Office 97 vs. Office 2010

In LotusScript when you create a Object af Word in Office 97, you can write something like this.

Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Set wdApp = CreateObject(“Word.Application”)
Set docNew = wdApp.Documents.Add(“L:\merge.doc”)
Dim doc As NotesDocument
Dim session As New NotesSession()
Set doc = uidoc.Document
With wdApp.ActiveDocument.Bookmarks
.Item(“Nummer”).Range.Text = uidoc.FieldGetText( “number” )
.Item(“User”).Range.Text = uidoc.FieldGetText( “User” )
…….
End With
wdApp.visible = True

This will open a Word document and put some tekst from a Notes document in it. But if you use this code with Office 2010 you will get a error.

Type Mismatch i method NRun: FROMVAR found, Unknown expected

This is because the create Object has not yet started, when this scrips run. Office 2010 is to slow. It works when you run i debug mode, but not if you run it without.

One workaround is to put a sleep statement in code.

Ex.

Set wdApp = CreateObject(“Word.Application”)
Sleep(3) ‘waits 3 seconds
Set docNew = wdApp.Documents.Add(“L:\merge.doc”)

Try if you can get it down to 1 or 2. Depending on your network and CPU

Then the Word Document will open without errors

This entry was posted in Lotus, Tip and tagged , , , . Bookmark the permalink.