INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

MS Word & Outlook OLE

Create a word doc and send it via Outlook by mbalent
Posted: 3 Mar 05

Here is some sample script.  The word document created is saved from a template doc previously created with specific bookmarks used to format the text.

CODE

oleobject lole_word
OLEObject lole_item, lole_attach, lole_outlook
string ls_file_name

lole_word = CREATE oleobject
lole_outlook = Create OLEObject
TRY
    lole_word.connecttonewobject('word.application')
CATCH (runtimeerror a)
    Messagebox('Error','Error connecting with MS Word. Process terminating.')
    RETURN -1
END TRY
lole_word.visible = FALSE // dont want to see word

ls_file = C:\temp\template.doc

If Not FileExists(ls_file) Then
    //ERROR CONDITION
     li_rc = MessageBox("File Not Found", "Cannot find document template: "+ls_file+"~r"+ "Do you want to select the template?", Question!, YesNo!, 2)
     If li_rc = 2 Then
        Return -1
     Else
        GetFileOpenName("Select Template File", ls_file, ls_file_name, ".DOC","Template Files, *.DOC")
        If Not FileExists(ls_file_name) Then
            // ERROR CONDITION
            MessageBox("Template File Not Found","Cannot find document: "+ ls_file_name)
           return -1
        End If
     End If
ELSE
    
End If

TRY
    lole_word.Documents.open(ls_file_name)
CATCH (runtimeerror b)
    Messagebox('Error','Error opening ' + ls_file_name + ' with MS Word. Process terminating.')
    RETURN -1
    
END TRY
lole_word.activedocument.bookmarks.item('vendor').range.text = ids_xdex.getitemstring(1,'vendordesc')

lole_word.activedocument.bookmarks.item('buyertext').range.text = ls_buyernote
lole_word.activedocument.bookmarks.item('text').range.text = ls_data
lole_word.activedocument.bookmarks.item('legend').range.text = '* D - De Expedite, E - Expedite, C - Cancel'
lole_word.activedocument.bookmarks.item('buyer').range.text = ls_name
lole_word.activedocument.bookmarks.item('buyerfax').range.text = ls_fax
lole_word.activedocument.bookmarks.item('buyeremail').range.text = ls_email


is_doc = ls_file + ls_doc
// save document before processing further
TRY
    lole_word.activedocument.saveas(is_doc)
CATCH (runtimeerror c)
    Messagebox('Error','Error saving document ' + is_doc + '. Process terminating.')
    RETURN -1
END TRY
TRY
    lole_word.activedocument.saveas('P:\temp.doc') // save 'dummy' so 'real' document is not locked
CATCH (runtimeerror d)
    Messagebox('Error','Error saving temp document. Process terminating.')
    RETURN -1
END TRY

lole_word.activedocument.printout()    // print from word


//Connect to Outlook session using 'Outlook.Application'
li_rc = lole_outlook.ConnectToNewObject("outlook.application")

If li_rc <> 0 Then
    // ERROR CONDITION
          Messagebox("Outlook Error",string(li_rc))
          Destroy lole_outlook
          Return li_rc
End If
//Creates a new mail Item
lole_item = lole_outlook.CreateItem(0)
//Set the subject line of message
lole_item.Subject = "Expedite / De Expedite Notice"
//Body of mail message
lole_item.Body = "Please review the attached file and advise: "+Char(13)
//Recipient(s) Use a semicolon to separate multiple recipients
lole_item.To = dw_vendorfax.getitemstring(1,'contactemail')
lole_attach = lole_item.Attachments
lole_attach.add(is_doc)
lole_item.Display //displays the message
//    lole_item.Send //sends the message
lole_outlook.disconnectobject()

DESTROY lole_outlook
DESTROY lole_word

Back to Sybase: PowerBuilder FAQ Index
Back to Sybase: PowerBuilder Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close