Powerbuilder and excel VBA.

Hi,

From my powerbuilder 8.0 application, I have to open an excel file with some parameters and same parameters I want to use in excel VBA as commandline() for further process.

Kindly help

Thanks,

Nagendra
bssoftwareAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
berXpertConnect With a Mentor Commented:
Hi,

to open excel use Run() function, this way you can send parameters. Note than opening this way you wont be able to use it as an object, so your only interaction with excel will be your command line.

Try this to open XXX.XLS file in read only mode   /r  parameter :

Run('C:\Program Files\Microsoft Office\OFFICE11\excel.exe /r c:\xxx.xls')




Now in Excel to get Command Line you can try this function:



Option Explicit
'---API Declare---
Private Declare Function GetCommandLine Lib "KERNEL32" Alias "GetCommandLineA" () As String

'Purpose     :  Returns the command line
'Inputs      :  N/A
'Outputs     :  The command line used to initate Excel
'Author      :  Andrew Baker (www.vbusers.com)
'Date        :  25/11/2000 03:33
'Notes       :  To return meaningful command line information you must open the workbook
'               by shelling it as a parameter for Excel.exe, eg. using the following syntax:
'               "D:\Program Files\Microsoft Office\Office\EXCEL.EXE" /MyCommand "d:\command line.xls"
'               i.e. The path to Excel, then the command and finally the workbook.
'               Note the paths are encapsulated in double quotes.

'               NT USERS: YOU MUST OPEN EXCEL BY SHELLING IT USING THE SYNTAX GIVEN ABOVE.
'               IF A WORKBOOK IS OPENED BY DOUBLE CLICKING IT IN EXPLORER THIS API CALL WILL CAUSE A GPF.
'                
'Revisions   :

Function CommandLine() As String
    Static ssCmd As String
    If Len(ssCmd) = 0 Then
        ssCmd = GetCommandLine
    End If
    CommandLine = ssCmd
End Function

'Demonstration routine
'Place in the "ThisWorkbook" class
Private Sub Workbook_Open()
    Dim sCmd As String
    sCmd = CommandLine
    MsgBox "Command line: " & sCmd
End Sub




I hop this helps

BerX
0
 
namasi_navaretnamCommented:
Be more specific as to what the paramters are supposed to do within excel.

I am not sure if I understand this correctly. I understand you would like to pass some parameteres to excel. But, what would the paramteres do within excel? Depends on what needs to be done, I am sure there is a way.

regards-
0
 
Vikas_DixitCommented:
berXpert's solution is going to work well......

For the First part, You can also take a look at ShellExecuteEx function. For an example, go to :
http://www.experts-exchange.com/Programming/Programming_Languages/PowerBuilder/Q_20663647.html
For passing parameters, use the lpParameters member of the st_shellexecuteinfo structure.

Regards,
Vikas
0
 
namasi_navaretnamCommented:
You can do this also:

You can connect to excel and the pass the paramters into a excel and read the value from that cell internally if you need.

string ls_parm
oleobject lole_excel
lole_excel = create oleobject

ls_parm = 'Parm1 Parm2'

ll_result = lole_excel.ConnectToNewObject( "excel.application")
lole_excel.application.workbooks.add( )
lole_excel.activesheet.cells(1,1).value = ls_parm
lole_excel.application.visible = true
if isvalid(iole_object) then destroy iole_object

regards-
0
All Courses

From novice to tech pro — start learning today.