• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

Exporting

This should be real easy or impossible!

I need to give the users of the db I'm working on the ability to locate several documents, then export them to Word.

I know I can do an export whilst in a document and export to Word. I know I can use the @command to do the job. What I don't know is how to do this from LotusScript, so I can export the selected documents in a view rather than the view.

Doable or impossible?
0
gbentley
Asked:
gbentley
  • 4
  • 2
1 Solution
 
ZvonkoSystems architectCommented:

Doable :-)




Here a lately answered Q:
http://www.experts-exchange.com/Applications/Email/Lotus_Notes/Q_20443119.html

Tell me your Document fields and I can provide a short reduced version for your design basis.

So long,
Zvonko

0
 
gbentleyAuthor Commented:
zvonko - Thanks for the quick response. I was really after getting the whole document as formatted (exactly what you get if you open the document and choose File/Export) as there are a number of richtext fields.

I've found some code on the Sandbox, so I'll see how that goes for the moment.
0
 
ZvonkoSystems architectCommented:
Hey, I have never tried before this document-to-Word function.
I am excited! :-)

All the time I was doing it the hard way by using COM/OLE.

If you need some help with the Sandbox examples let me know.

So long,
Zvonko

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gbentleyAuthor Commented:
The sample I found also uses COM/OLE and the method is somewhat similar to yours, so don't get too excited!

I'll get back tomorrow with some news.
0
 
gbentleyAuthor Commented:
zvonko - Her is the code I came up with on the weekend. It does a mail merge into Word using the fields on the documents in the view it is run from. The Export Template documents just have a name and a template.

I make no claims to this being at all sturdy or perfect, but it is doing what I wanted and as the final format of the export is controlled by the merge document, it satisfies my users.

Sub Initialize
      Dim workspace As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim sourceView As NotesUIView
      Dim sourceDoc As NotesDocument
      Dim selectedDocs As NotesDocumentCollection
      
      Dim templateView As NotesView
      Dim templateDoc As NotesDocument
      Dim templateNames() As String
      Dim selectedTemplateNameV As Variant
      
      Dim wordDocs As Variant
      Dim wordDoc As Variant
      Dim wordObj As Variant
      Dim range As Variant
      Dim tableObj As Variant
      Dim object As Variant
      Dim rtitem As Variant
      
      Dim i As Integer
      Dim rowNum As Integer
      Dim tempString As String
      
      Set db =workspace.CurrentDatabase.Database
      
      
      Set templateView = db.GetView("Templates")
      If templateView.AllEntries.Count < 1 Then ' No Templates
            Msgbox "You need to create some Templates before you can use the Export facility!"
            Exit Sub
      Elseif templateView.AllEntries.Count = 1 Then ' One Template, no need to prompt
            Set templateDoc = templateView.GetNthDocument(1)
      Else ' Get list of template names from Templates view
            Redim templateNames(1 To templateView.AllEntries.Count)
            For i = 1 To templateView.AllEntries.Count
                  templateNames(i) = templateView.GetNthDocument(i).GetFirstItem("ExportTemplateName").Text
            Next
            ' Get users selection
            selectedTemplateNameV = workspace.Prompt( PROMPT_OKCANCELLIST, "Templates", _
            "Please select a template to use for your export.", _
            templateNames(1), _
            templateNames)
            If selectedTemplateNameV = "" Then ' Exit on Cancel or no selection
                  Exit Sub
            End If
            ' Select chosen Template to use for export
            Set templateDoc = templateView.GetDocumentByKey( selectedTemplateNameV, True)
      End If
      
      'Get documents selected in View
      Set selectedDocs = db.UnprocessedDocuments
      Set sourceDoc = selectedDocs.GetFirstDocument
      If sourceDoc Is Nothing Then
            Exit Sub
      End If
      
      ' Create merge source doc and table
      Set wordObj = CreateObject("Word.Application.8")
      wordObj.visible = True
      Set wordDocs = wordObj.Documents
      wordDocs.Add
      Set wordDoc = wordObj.ActiveDocument
      Set range = wordDoc.Range(0,0)
      Set tableObj = wordObj.selection.Tables.Add(range,selectedDocs.Count+1,Ubound(sourceDoc.Items))
      ' Add column headings from field names
      For i = Lbound(sourceDoc.Items) To Ubound(sourceDoc.Items)
            tableObj.cell(1,i).select      
            wordObj.selection.typetext sourceDoc.Items(i).Name
      Next
      
      rowNum = 2
      'Process each document
      While Not(sourceDoc Is Nothing)
            ' Export documents fields to Word table
            For i = Lbound(sourceDoc.Items) To Ubound(sourceDoc.Items)
                  Call TableObj.cell(rowNum,i).select
                  tempString = sourceDoc.Items(i).Text
                  wordObj.selection.typetext tempString
            Next
            rowNum = rowNum + 1
            Set sourceDoc = selectedDocs.GetNextDocument(sourceDoc)
      Wend
      
      ' Save data file
      wordDoc.saveas "C:\temp\data.doc"
      wordDoc.close
      
      ' Get template from doc
      Set rtitem = templateDoc.GetFirstItem("ExportTemplateTemplate")
      
      ' Trap error on no attachment
      On Error Resume Next
      Forall o In rtitem.EmbeddedObjects
            If ( o.Type = 1453 ) Then
                  Set object = o
            End If
      End Forall
      On Error Goto 0
      
      ' Exit if no attachment
      If object Is Nothing Then
            Msgbox "That template has no attached file. Please attach a merge document and retry."
            wordObj.quit
            Exit Sub
      End If
      
      Set wordDoc = object.Activate(True)
      ' Perform merge to document
      wordDoc.MailMerge.MainDocumentType = wdFormLetters
      wordDoc.MailMerge.OpenDataSource "C:\temp\Data.doc"
      wordDoc.MailMerge.SuppressBlankLines = True
      wordDoc.MailMerge.Execute True
      Msgbox "Export Complete"
End Sub

Regards
Gordon
0
 
gbentleyAuthor Commented:
zvonko - I gave you the points to close the question and because you gave me the link that got me started.

The code I posted (plus a few mods) has worked well for me. Feel free to use/abuse as you want.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now