Wednesday, January 2, 2013

Accessing Word in PowerBuilder

integer li_rtn
string ls_program
 
ls_program = "c:\msoffice\winword\winword.exe " + &
 "c:\msoffice\winword\unleash.doc"
li_rtn = Run( ls_program, Minimized!)
If li_rtn = -1 then
   MessageBox( "Run Error", "Could not start Word for Windows")
   Return
Else
   il_ddehandle = OpenChannel( "WINWORD", "c:\msoffice\winword\unleash.doc")
   If il_ddehandle < 0 Then
      MessageBox( "Connection Error", "Word is not responding!")
      Return
   End If
End If
 
 

Sending Data

To send data to a DDE server, use the SetRemote() function.
 
SetRemote( "last_name", "Herbert", "Winword", "unleash.doc") 

Requesting Data

If you want to retrieve information from the DDE server application, use the GetRemote() function.

string ls_LastName
GetRemote( "last_name",ls_LastName,"Winword","unleash.doc")

Command
li_rtn = ExecRemote( "FileSave", li_ddehandle)
 
Terminating 
 li_rtn = CloseChannel(il_ddehandle)
If li_rtn <> 1 Then
   MessageBox("Close error","Unable to terminate conversation!")
End If
 
 
OLEObject ole_excel
string ls_string
integer li_int
any la_any
ole_excel = CREATE OLEObject
ole_excel.ConnectToObject( "budget.xls")
la_any = ole_excel.application.cells(10,5).value
Choose Case ClassName( la_any)
   Case "string"
      ls_string = la_any
   Case "int"
      ls_int = la_any
   Case Else
      MessageBox( "Retrieve Error","Unknown data type returned")
      Return
End Choose 

No comments:

Post a Comment