Manage Learn to apply best practices and optimize your operations.

Word Subroutines

You can use these routines to output data directly to Word regardless of the version they're running. We use these for a lot of reports and even to created quotes via protected Word documents. I recommend sticking them into a library then just including them whenever you like.

Sub NewWordDoc(msword As Variant, worddoc As Variant, IsVisible As Variant)
'msword and worddoc are for passing back control of the instance of word an the new word document respectively
'IsVisible is for determining whether on not to make the instance of Word visible

'Create an instance of Word
Set msword = CreateObject("Word.Application")
Set docs = msword.Documents
msword.Visible = IsVisible
'Create a new word document and set it to active
Call docs.Add
Set worddoc = docs(1)
?Open an existing Word Document
Call msword.Documents.Open("""c:initiatives.doc""")

End Sub

Sub AttachWord(worddoc As Variant, rtitem As NotesRichTextItem, filename$)
'Saves the Ms Word document as filename$ then attaches it as an object to the rich text item. Useful for attaching the Word document to a Notes document

Dim object As NotesEmbeddedObject
Call SaveWord(worddoc, filename$)
Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", filename$, "thewordfile" )
Call rtitem.AddNewLine( 1 )

End Sub

Sub SaveWord(worddoc As Variant, filename$)
'Saves the Word document as filename$

worddoc.SaveAs filename$

End Sub

Sub AddWordTextAndLink(worddoc As Variant, mytext$, mylink$)
'Adds the text in mytext$ to the Word document then makes it a link the the address in mylink$ then moves down to the next line

Call worddoc.Activewindow.Selection.TypeText(mytext$)
Call worddoc.Activewindow.Selection.HomeKey(5, 1)
Call worddoc.Hyperlinks.Add(worddoc.Activewindow.Selection.Range, mylink$ , "")
Call worddoc.Activewindow.Selection.TypeText(Chr$(13) + Chr$(13))

End Sub

Sub AddWordText(worddoc As Variant, myText$)
'Adds the text in mytext$ to the Word document then moves down to the next line

Call worddoc.Activewindow.Selection.TypeText(mytext$ + Chr$(13))

End Sub

Sub CloseWord(msword As Variant, worddoc As Variant)
'Closes the Word document then closes the instance of Word


End Sub

Dig Deeper on Domino Resources - Part 5

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...