Solved

Powerbuilder and excel VBA.

Posted on 2004-04-02
7
1,036 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:bssoftware
  • 2
7 Comments
 
LVL 15

Expert Comment

by:namasi_navaretnam
Comment Utility
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
 
LVL 5

Accepted Solution

by:
berXpert earned 50 total points
Comment Utility
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
 
LVL 8

Expert Comment

by:Vikas_Dixit
Comment Utility
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
 
LVL 15

Expert Comment

by:namasi_navaretnam
Comment Utility
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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now