1. Dennis Little
  2. PowerBuilder
  3. Tuesday, 13 August 2024 18:11 PM UTC

Hello all,

We're working on a project that will open Excel, call a stored procedure, create a chart, print as a pdf then close.

Using PB2022R2 Build 2828.

Thanks to Tobias we have a very nice OLE example that does everything we need, except the ability to add arguments. We've done that thru a command line in the past, but was hoping to build on the OLE code.

It looks like Excel-VBA will allow arguments, just not sure of the OLE syntax. 

Excel sample -  Application.Run "'" & wb.Name & "'!routine_name", True

Thanks,

Dennis

Tobias' example

oleobject ole_excel
ole_excel = create oleobject
ll_ret = ole_excel.ConnectToNewObject("Excel.Application")
if ll_ret <> 0 then
MessageBox("Error", "Could not create Excel object (" + string(ll_Ret) + ")!~nIs Microsoft Excel installed?", Exclamation!)
destroy ole_excel
end if
ole_excel.Visible = true;
// PDF speichern
ole_excel.WorkBooks.Open(ls_source)
oleobject lole_worksheet,lole_workbook
lole_workbook = ole_excel.application.workbooks(1)
lole_worksheet = lole_workbook.worksheets(1)
lole_worksheet.SaveAs(ls_pdf, 57);
ole_excel.Quit()
ole_excel.DisconnectObject()

John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 13 August 2024 19:05 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Dennis -

The online library reference for Visual Basic for Applications describes the object model for Office apps:

    https://learn.microsoft.com/en-us/office/vba/api/overview/library-reference

I keep this URL as a shortcut in my browser.

By using the navigation pane on the left side, the description for Excel's Application.Run method can be found here:

    https://learn.microsoft.com/en-us/office/vba/api/excel.application.run

I've not tried to do this, but it appears the steps are relatively simple.

Once the workbook is open, get a reference to the Excel Application object as a PB OleObject, then invoke the Run method, supplying the name of the macro and up to 30 arguments.

Best regards, John

Comment
There are no comments made yet.
Dennis Little Accepted Answer Pending Moderation
  1. Thursday, 15 August 2024 19:58 PM UTC
  2. PowerBuilder
  3. # 2

John,

Thanks for the info.

 I will do some experimenting.

Dennis

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.