About This Code
Brief Description:
How to export data From Notes document to MS Word using Lotussscript action button?
Last Modified:
28 Mar 2008
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
Hi!
I have a big problem. I need to do the following thing:
I have a Notes database where is a lot of documents, when i'm opening one document than there is an Action button which when pressed, opens an MS Word document and export all Notes document data to the MS Word document.
The only thing i know, is to open blank Word document with this code (see in Usage/Example), But i don't know, how to put Notes data into Word document!
It's seems to be a very easy LotusScript but i don't know how to do that, but i need this Lotus Script with Action Button.
Can anyone help me please? I will be very pleased if someone can give a sample code or good advice how to do that or a hyperlink to web page where is information about my problem!
Best regards, Guntis!
Usage / Example
Sub Click(Source As Button)
Dim visibility As Boolean
Dim wApp As Variant
Set wApp=CreateObject("Word.Application")
wApp.Visible=visibility
Call wApp.Documents.Add()
wApp.Visible = True
End Sub
Comments
Posted by Stefano Parmeggiani on 03/28/2008 03:14:20 AMTry here
http://www.parme.it/wordpress/2008/03/07/compilare-documenti-word-da-lotusscript/
Posted by Guntis Koks on 03/28/2008 05:00:26 AM...
No, this code in that link is not working, maybe because this is VB code, not Lotus Notes.
maybe i should define my form fields somewhere and then print them to the word document, hmmm, but i don't know how.
Posted by Guntis Koks on 03/28/2008 07:51:38 AMI figured it out :)
This example just select's all text/fields/images e.t.c, than makes a copy of notes document and paste it in word document:
Sub Click(Source As Button)
Dim wApp As Variant
Dim doc As Variant
Dim r As Variant
Dim rval As Variant
Dim body As Boolean
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim text As String
Set uidoc = workspace.CurrentDocument
Call uidoc.SelectAll
Call uidoc.Copy
Set wApp=CreateObject("Word.Application")
wApp.Visible=visibility
Call wApp.Documents.Add()
wApp.Visible = True
wApp.Selection.Paste
End Sub
Posted by Joseph Hoetzl on 04/17/2008 01:16:26 PMSetup form fields in word doc and then..
Maybe this code snippet will help you out..
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As notesdatabase
Dim view As notesview
Dim uidoc As NotesUIDocument
Dim currdb As NotesDatabase
Dim item As NotesItem
Dim WrdTempNotesdoc As NotesDocument
Dim SurveyDoc As NotesDocument
Set db = session.CurrentDatabase
Dim SurveyType As String
Set uidoc = workspace.CurrentDocument
Set SurveyDoc = uidoc.document
SurveyType="2007"
'Get The template doc and detach it
Set view = db.GetView("vwWordTemplateLookup")
Set WrdTempNotesdoc = view.GetDocumentByKey(SurveyType)
'Make sure we have the template form in the notes side
If WrdTempNotesdoc Is Nothing Then
Beep
Msgbox("ERROR: Word Template file not found. Operation Aborted")
Exit Sub
End If
'Make sure the template form has a word template on it
Set rtitem = WrdTempNotesdoc.GetFirstItem("TemplateMSWordDot")
If Isempty(rtitem.EmbeddedObjects) Then
Beep
Msgbox("ERROR: Word Template file not found. Operation Aborted")
Exit Sub
End If
' Mkdir "c:\temp"
'Export the word template to the hard drive
Forall embObj In rtitem.EmbeddedObjects
thetemplate$ = embObj.Source
Set wordobject = rtitem.GetEmbeddedObject(thetemplate$)
filepath = "c:\"
filename$ = filepath & thetemplate$
Call wordobject.ExtractFile(filename$)
Exit Forall
End Forall
'Get all the data we need to pass into the word template
Dim ContactName As String
Dim CompanyName As String
Dim email As String
Dim ip As String
Dim SurveyDate As String
Dim q11 As String, q12 As String, q13 As String, q14 As String, q15 As String, q16 As String
Dim q21 As String, q22 As String, q23 As String , q24 As String, q25 As String, q26 As String
Dim q31 As String, q32 As String, q33 As String , q34 As String, q35 As String, q36 As String
Dim q41 As String, q42 As String, q43 As String , q44 As String, q45 As String, q46 As String, q47 As String
Dim q51 As String, q52 As String, q53 As String , q54 As String, q55 As String
Dim q61 As String, q62 As String, q63 As String , q64 As String, q65 As String, q66 As String, q67 As String, q68 As String
Dim q70 As String, q80 As String
ContactName = uidoc.FieldGetText("name")
CompanyName = uidoc.FieldGetText("company")
email = uidoc.FieldGetText("email")
ip = SurveyDoc.IP(0)
SurveyDate = surveydoc.Created
q11 = SurveyDoc.q11(0)
q12 = SurveyDoc.q12(0)
q13 = SurveyDoc.q13(0)
q14 = SurveyDoc.q14(0)
q15 = SurveyDoc.q15(0)
q16 = SurveyDoc.q16(0)
q21 = SurveyDoc.q21(0)
q22 = SurveyDoc.q22(0)
q23 = SurveyDoc.q23(0)
q24 = SurveyDoc.q24(0)
q25 = SurveyDoc.q25(0)
q26 = SurveyDoc.q26(0)
q31 = SurveyDoc.q31(0)
q32 = SurveyDoc.q32(0)
q33 = SurveyDoc.q33(0)
q34 = SurveyDoc.q34(0)
q35 = SurveyDoc.q35(0)
q36 = SurveyDoc.q36(0)
q41 = SurveyDoc.q41(0)
q42 = SurveyDoc.q42(0)
q43 = SurveyDoc.q43(0)
q44 = SurveyDoc.q44(0)
q45 = SurveyDoc.q45(0)
q46 = SurveyDoc.q46(0)
q47 = SurveyDoc.q47(0)
q48 = SurveyDoc.q48(0)
q51 = SurveyDoc.q51(0)
q52 = SurveyDoc.q52(0)
q53 = SurveyDoc.q53(0)
q54 = SurveyDoc.q54(0)
q55 = SurveyDoc.q55(0)
q61 = SurveyDoc.q61(0)
q62 = SurveyDoc.q62(0)
q63 = SurveyDoc.q63(0)
q64 = SurveyDoc.q64(0)
q65 = SurveyDoc.q65(0)
q66 = SurveyDoc.q66(0)
q67 = SurveyDoc.q67(0)
q68 = SurveyDoc.q68(0)
q70 = SurveyDoc.q70(0)
If q70 = "1" Then
q70 = "Yes"
Else
q70 = "No"
End If
q80 = SurveyDoc.q80(0)
'Create a empty word app
Dim wdApp As Variant
Dim wdDoc As Variant
Set wdApp = CreateObject("Word.application")
'Open the template we detached above and hide the app
'set to false for prod!
wdApp.visible=True
Set wdDoc = wdApp.Documents.Add(filepath & thetemplate$)
'Blank template now loaded
'wish the form designer had the number sequenced a bit better!!!
If SurveyType = "2007" Then
With wdDoc
.FormFields("ContactName").result = ContactName
.FormFields("CompanyName").result = CompanyName
.FormFields("emailaddress").result = email
' .FormFields("IP1").result = ip
.FormFields("s11").result = q11
.FormFields("s12").result = q12
.FormFields("s13").result = q13
.FormFields("s14").result = q14
.FormFields("s15").result = q15
' .FormFields("s1comments").result = q16
'need to use typetext for longer text entries...
wdDoc.Bookmarks("s1comments").Select
Call wdApp.Selection.TypeText(q16)
'Section 2
.FormFields("s21").result = q21
.FormFields("s22").result = q22
.FormFields("s23").result = q23
.FormFields("s24").result = q24
.FormFields("s25").result = q25
'.FormFields("s2comments").result = q26
wdDoc.Bookmarks("s2comments").Select
Call wdApp.Selection.TypeText(q26)
'Section 3
.FormFields("s31").result = q31
.FormFields("s32").result = q32
.FormFields("s33").result = q33
.FormFields("s34").result = q34
.FormFields("s35").result = q35
.FormFields("s3comments").result = q36
'Section 4
.FormFields("s41").result = q41
.FormFields("s42").result = q42
.FormFields("s43").result = q43
.FormFields("s44").result = q44
.FormFields("s45").result = q45
.FormFields("s46").result = q46
.FormFields("s47").result = q47
.FormFields("s4comments").result = q48
'Section 5
.FormFields("s51").result = q51
.FormFields("s52").result = q52
.FormFields("s53").result = q53
.FormFields("s54").result = q54
' .FormFields("s5comments").result = q55
wdDoc.Bookmarks("s5comments").Select
Call wdApp.Selection.TypeText(q55)
'Section 6
.FormFields("s61").result = q61
.FormFields("s62").result = q62
.FormFields("s63").result = q63
.FormFields("s64").result = q64
.FormFields("s65").result = q65
.FormFields("s66").result = q66
.FormFields("s67").result = q67
.FormFields("s6comments").result = q48
.FormFields("s80").result = q80
.FormFields("s70").result = q70
.FormFields("ipaddress").result = IP
.FormFields("Date").result = SurveyDate
.FormFields("ContactName2").result = ContactName
End With
End If
' wdApp.Visible = True