Link to home
Start Free TrialLog in
Avatar of TSO Fong
TSO FongFlag for Sweden

asked on

(stamp?) Merge Word attachments into 1 doc

Greetings --

stamp provided a script in this question: https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=11935798

The script takes the documents you have selected in a view and merges any Word attachments in those documents into one new Word document.

The script works great, but I need to refine it a bit.

stamp's script begins:

++++ Begin Copy ++++

Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim collection As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim word As Variant
    Dim extname As String
    Dim i As Integer

    Set db = session.CurrentDatabase
    Set collection = db.UnprocessedDocuments
    Set word = CreateObject("Word.Document")
    word.Application.Visible = True

+++++ End Copy +++++

Is there any way to indicate which Word template should be used to create the word document? The files being merged are all created on a specific template, with specific styles attached. When they are merged in this way, the new document is created on the Normal.dot template.

If the template cannot be specified through LotuScript, could the above be changed to launch the first attachment (as an unnamed file?), and then append any other Word attachments to it?

Thanks in advance!

-- b.r.t.
Avatar of sloeber
sloeber
Flag of Belgium image

Yes, it's possible

Dim word as variant
set word = createobject("word.application.8)
word.documents.open"c:/wordtemplate.dot"
word.obj.visible = True
............
...........
...............

If it's neccessary you can make an inputbox, so that the user can choose which template he wants to use

Greets
Sloeber
Avatar of TSO Fong

ASKER

Sloeber --

In the line,

set word = createobject("word.application.8)

There is only one quote mark. This syntax strikes me as unlikely.

At first I thought the 8 was a typo, but that wouldn't explain why there is a period before it.

Can you please clarify this for me?

Thanks!
-- b.r.t.
ASKER CERTIFIED SOLUTION
Avatar of sloeber
sloeber
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The previous example I gave you, was an example if you had saved your template as a document.
Here's an exapmle if you want to open a template, put in your values and saved it as a document.The Documents.Add method allows you to create a new document using any template you wish.

Its syntax is:

expression.Add( Template, NewTemplate )

expression Required. An expression that returns a Documents object.

Template Optional Variant. The name of the template to be used for the new document. If this argument is omitted, the Normal template is used.

NewTemplate Optional Variant. True to open the document as a template. The default value is False.

- - -

To use this from Notes you can do something like:

'Define the required Microsoft Word objects
Dim wordApp As Variant 'Word Application object
Dim wordDoc As Variant 'Word Document object
Dim wordWindow As Variant 'Word Window object

'Hook it into Word
Set wordApp = CreateObject( "Word.Application" )
wordApp.Visible = True 'Make Word visible

'Add a new document based on the 'sometemplate' template
Set wordDoc = wordApp.Documents.Add( "sometemplate.dot")

Set wordWindow = wordDoc.ActiveWindow 'Grab the active window

Greets,
Sloeber

Thank you, Sloeber. This seems to be working well for me!