Domino Code Fragment

Code Name*
Import information from a Word document into a Notes document
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.220.136.165
Description*
This script imports information from a Word document into a Notes document while standardizing the doc's formatting.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
This script imports information from a Word document into a Notes document while standardizing the doc's formatting. This was
possible because all of the source documents had approx. the same format. It would be better to have the user put the doc into
a word form containing fixed field tags, or better yet just put it into Notes to begin with. This is used to get newsletter
articles into a Notes database available on the intranet.



Sub Initialize
    Dim Session As New NotesSession
    Dim uiWsp As New NotesUIWorkspace
    Dim uiDoc As NotesUIDocument
    Dim doc As NotesDocument
    Dim rtArtField As Variant
    Dim articleText As String
    Dim articleLines() As String
    Dim a As String, a2 As String
    Dim build As String


     Set uidoc = uiWsp.CurrentDocument
    Set doc = uiDoc.Document
    uiDoc.EditMode = True


' Skip the whole thing if nothing was imported
    articleText = uiDoc.FieldGetText("BODY")
    If Trim$(articleText) = "" Then End


     ' Save the document to make RT fields accessible
    uiDoc.Save


     ' Get Body as a Rich Text Item
    Set rtArtField = doc.GetFirstItem( "Body" )
    If ( rtArtField.Type <> RICHTEXT ) Then
         Msgbox "Rich text field 'Body' not found!"
         End
    End If


  ' Get the formatted text  from the field, don't wrap at all
    articleText = rtArtField.GetFormattedText(0, 5000)


     ' Make sure article ends with a CRLF
    If Right$(articleText,1) <> Chr$(10) Then
         articleText = articleText & Chr$(13) & Chr$(10)
    End If


' Break the text stream into lines in an array.
    ' Each element is a line (paragraph) termed
    ' by a CRLF
    ' Also convert fancy single & double quotes to normal ones
    element = 1
    For i= 1 To Len(articleText)
         a = Mid$(articleText, i,1)
         If Asc(a) = 145 Or Asc(a) = 146 Then a = Chr$(39)
         If Asc(a) = 147 Or Asc(a) = 148 Then a = Chr$(34)
         If Asc(a) <> 13 Then
              build = build & a
         Else
              Redim Preserve ArticleLines(element)
              articleLines(element - 1) = build & Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)
              element = element + 1
              build = ""
              i = i + 1
              If i > Len(articleText) Then Exit For
         End If
    Next


     ' The first significant non-blank line is the title of the article
    a = ""
    i = 0
' Skip lines with a few characters, these sometimes show in Word imports


 ' (Count includes 2 pairs of CRLFs at end of each line)
    While Len(Trim$(a)) < 7
         a = articleLines(i)
         i=i+1
         If i > Ubound(articleLines) And a = "" Then a = "Blank Article"
    Wend


     ' Put title in Description field (yep!?!) minus CRLF
    doc.Description = Left$(a, Len(a) -4)


     ' The first line containing 'date:' is the date line
    x = 0
    i= -1
    While x = 0
         i=i+1
         x =  Instr(1 ,articleLines(i) , "ate:", 1 )
         If i >= Ubound(articleLines) And x = 0 Then x = 4
    Wend


     ' Format it & put it in Subject field
    a = "Power Points Articles - " & Right$(articleLines(i),  (Len (articleLines(i)) - x) - 4)
    doc.Subject =  Left$(a, Len(a) -4)


     ' Skip the volume line, find next non-blank for article. Reload the RT field to
    ' get rid of header stuff there.


     i = i + 2
    a = ""
    While Trim$(a) = ""
         i=i+1
         a = articleLines(i)
    Wend


     a = ""
    For x = i To Ubound(ArticleLines)
         a = a + ArticleLines(x)
    Next


     ' Remove any trailing control characters (CRLF)
    While Asc(Right$(a, 1)) < 32
         a = Left$(a, Len(a) -1)
    Wend


     uiDoc.FieldClear("BODY")
    uiDoc.FieldSetText "BODY", a


     uiDoc.GotoTop

    ' Get the saved article order variable
    a2 = Session.GetEnvironmentString("ArticleSeq")
    If a2 = "" Then a2 = "0"


     ' Increment it, save it, set ArticleOrder field with it
    If Isnumeric(a2) Then
         a2 = Str$(Val(a2) + 1)
    Else
         a2 = "0"
    End If
    Session.SetEnvironmentVar "ArticleSeq", a2
    uiDoc.FieldSetText "ArticleOrder", a2


 ' Save the results
    uiDoc.Save


End Sub