nbtnotes
asked on
LotusScript: Merge Data to Word File
I have an Agent that works on my Domino Client however it fails every time when it is run on the Domino Server.
I receive a "Variant does not contain an object" on the following line of code.
Call objDocs.Add(templateDir)
Any ideas why it is working on the Domino Client and not the Server?
FYI: I run the agent via a Notrix Job. For those not familiar Notrix, it is like LEI.
Code:
Sub Initialize
Dim objWord As Variant, objDocs As Variant, objDoc As Variant
Dim templateDir As String
Set objWord = Nothing
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Applica tion")
End If
objWord.Visible = False
objWord.ActivePrinter = ""
On Error GoTo ErrorHandler
Set objDocs = objWord.Documents
templateDir = "C:\Template Files\Template.docx"
Call objDocs.Add(templateDir)
Set objDoc = ObjDocs(1)
objDoc.Activate
objDoc.FormFields("Custome rName").Re sult = "TEST TEST TEST TEST"
ExitSub:
objDoc.SaveAs2 "C:\Saved Files\Template-1234.pdf", 17
objDoc.Close(0)
Set objDoc = Nothing
Set objDocs = Nothing
objWord.Quit
Set objWord = Nothing
GoTo AgentExit
ErrorHandler:
objDoc.Close(0)
Set objDoc = Nothing
Set objDocs = Nothing
objWord.Quit
Set objWord = Nothing
Resume AgentExit
AgentExit:
End Sub
I receive a "Variant does not contain an object" on the following line of code.
Call objDocs.Add(templateDir)
Any ideas why it is working on the Domino Client and not the Server?
FYI: I run the agent via a Notrix Job. For those not familiar Notrix, it is like LEI.
Code:
Sub Initialize
Dim objWord As Variant, objDocs As Variant, objDoc As Variant
Dim templateDir As String
Set objWord = Nothing
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Applica
End If
objWord.Visible = False
objWord.ActivePrinter = ""
On Error GoTo ErrorHandler
Set objDocs = objWord.Documents
templateDir = "C:\Template Files\Template.docx"
Call objDocs.Add(templateDir)
Set objDoc = ObjDocs(1)
objDoc.Activate
objDoc.FormFields("Custome
ExitSub:
objDoc.SaveAs2 "C:\Saved Files\Template-1234.pdf", 17
objDoc.Close(0)
Set objDoc = Nothing
Set objDocs = Nothing
objWord.Quit
Set objWord = Nothing
GoTo AgentExit
ErrorHandler:
objDoc.Close(0)
Set objDoc = Nothing
Set objDocs = Nothing
objWord.Quit
Set objWord = Nothing
Resume AgentExit
AgentExit:
End Sub
I am not an expert in this even tho I work for IBM. But looking at the code isn't it looking for things that are on the client and not on the server. I wouldn't think this would work on the server, I could be wrong.
I see, its looking for the Template folder which is only found on the client side not on the server.
Set objDocs = objWord.Documents
templateDir = "C:\Template Files\Template.docx"
Call objDocs.Add(templateDir)
Set objDoc = ObjDocs(1)
objDoc.Activate
Set objDocs = objWord.Documents
templateDir = "C:\Template Files\Template.docx"
Call objDocs.Add(templateDir)
Set objDoc = ObjDocs(1)
objDoc.Activate
ASKER
"C:\Template Files\Template.docx" is the location on both the Client and Server Side.
I think there is a difference between the Client and Server editions. Just not sure what it is.
I think there is a difference between the Client and Server editions. Just not sure what it is.
Could it be permissions to the folder on the server side? I am just grasping at straws here.
A Windows server, I hope, and not Linux? You could check the Windows logs, to see which exact error occurs.
ASKER
Sjef,
Can you give some assistance on where exactly to look for the Windows Server Log?
We rerun the agent and nothing appears in the Event Viewer. Looking in the wrong place?
Can you give some assistance on where exactly to look for the Windows Server Log?
We rerun the agent and nothing appears in the Event Viewer. Looking in the wrong place?
ASKER
Does not appear to be any errors appearing in the Windows Event viewer.
I am starting to wonder if the Server Install is missing some files the Client Install has. Class files and etc.
I am starting to wonder if the Server Install is missing some files the Client Install has. Class files and etc.
I suppose you'd have seen other errors if classes were missing. How do you know the line with the error is the one you indicated? You could add one line, like this:
ErrorHandler:
MsgBox "Error: " & Error$ & " on line " & Erl
Call objDoc.Close(0)
What's kind of unfortunate: sometimes the numbering of lines in the Designer does not correspond with the number printed with Erl... But there seems to be an Action or Tool option to go to the line using a number.
ErrorHandler:
MsgBox "Error: " & Error$ & " on line " & Erl
Call objDoc.Close(0)
What's kind of unfortunate: sometimes the numbering of lines in the Designer does not correspond with the number printed with Erl... But there seems to be an Action or Tool option to go to the line using a number.
ASKER
[11C8:0002-0DF0] 04/18/2016 02:39:20 PM Notrix: Agent printing: Error: Microsoft Word: Word was unable to read this document. It may be corrupt. Try one or more of the following: * Open and Repair the file. * Open the file with the Text Recovery convert
ASKER
I go to the server and I can open the file without any issues.
ASKER
I created a new docx file and added the merge field. Still the same result.
Just wondering (I don't know too much about Windows servers): is Word started from a user account or from a server account? If the Domino server runs as a service, its environment is not the same as a user environment. How and where I don't know. Anyway, the Domino service can be started under a specific user account, maybe that solves this issue...
ASKER
I can run the following locally and not on the server.
I receive an automation error on the following line of code:
Set doc = wApp.documents.Add()
Sub Initialize
Dim wApp As Variant
Dim doc As Variant
Set wApp = CreateObject("Word.applica tion")
wApp.Application.Visible = True
Set doc = wApp.documents.Add()
wApp.Selection.TypeText "add some text"
wApp.Selection.Paste
ExitSub:
doc.SaveAs2 "C:\Enoble\Saved Files\NOA-1234.pdf", 17
doc.Close(0)
Set doc = Nothing
wApp.Quit
Set wApp = Nothing
GoTo AgentExit
ErrorHandler:
Print "Error: " & Error$ & " on line " & Erl
doc.Close(0)
Set doc = Nothing
wApp.Quit
Set wApp = Nothing
Resume AgentExit
AgentExit:
End Sub
I receive an automation error on the following line of code:
Set doc = wApp.documents.Add()
Sub Initialize
Dim wApp As Variant
Dim doc As Variant
Set wApp = CreateObject("Word.applica
wApp.Application.Visible = True
Set doc = wApp.documents.Add()
wApp.Selection.TypeText "add some text"
wApp.Selection.Paste
ExitSub:
doc.SaveAs2 "C:\Enoble\Saved Files\NOA-1234.pdf", 17
doc.Close(0)
Set doc = Nothing
wApp.Quit
Set wApp = Nothing
GoTo AgentExit
ErrorHandler:
Print "Error: " & Error$ & " on line " & Erl
doc.Close(0)
Set doc = Nothing
wApp.Quit
Set wApp = Nothing
Resume AgentExit
AgentExit:
End Sub
ASKER
I believe it's some sort of UI issue.
What's your Office version, on the server and locally, and what versions of Notes and Domino do you currently use?
I have this code to start Word:
I have this code to start Word:
Function CreateMSWordDocument As Variant
Dim msWord As Variant
On Error Goto CreateNewInstance
Set msWord = GetObject("", "Word.Application")
Done:
Set CreateMSWordDocument = msWord
Exit Function
CreateNewInstance:
Print "Loading Microsoft Word.... Please Wait...."
Err = 0
Set msWord = CreateObject("Word.Application")
Print "Microsoft Word Loaded"
Resume Done
End Function
ASKER
Word 2013 on Both
Notes 9 on both Client and Server
I receive an error if I add the file reference.
04/19/2016 11:52:47 AM Getting Microsoft Word.... Please Wait....
04/19/2016 11:52:47 AM Error: Automation object error on line 8
04/19/2016 11:52:47 AM Loading Microsoft Word.... Please Wait....
04/19/2016 11:52:48 AM Microsoft Word Loaded
Notes 9 on both Client and Server
I receive an error if I add the file reference.
04/19/2016 11:52:47 AM Getting Microsoft Word.... Please Wait....
04/19/2016 11:52:47 AM Error: Automation object error on line 8
04/19/2016 11:52:47 AM Loading Microsoft Word.... Please Wait....
04/19/2016 11:52:48 AM Microsoft Word Loaded
Sub Initialize
Dim msWord As Variant
On Error GoTo CreateNewInstance
Print "Getting Microsoft Word.... Please Wait...."
Set msWord = GetObject("C:\TemplateFile.docx", "Word.Application")
Done:
Print "DONE"
Exit Sub
CreateNewInstance:
Print "Error: " & Error$ & " on line " & Erl
Print "Loading Microsoft Word.... Please Wait...."
Err = 0
Set msWord = CreateObject("Word.Application")
Print "Microsoft Word Loaded"
Resume Done
End Sub
ASKER
Here is the file I am attempting to access.
TemplateFile.docx
TemplateFile.docx
They suggest here (https://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=56378756C2D9FF5185257E34006566DF) to add a sleep(1) call. No idea whether that'll do some good...
ASKER
Looks as thought there is an issue with running it via the Server. Can not get a hold of the Template File like it can via the Domino Client.
Even tried Word 2010.
Even tried Word 2010.
I'd expect some sort of error to be logged in the Windows logs. Which C:\ is referred to, on what system? Can that be traced in Windows? I know there is the Resource Monitor, but can it also monitor errors when opening files??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Read last comment