call visual-basic routin in an excel .xls

call visual-basic routin in an excel .xls

Postby NK » Thu Oct 05, 2006 12:54 pm

Hello Fivewinners,

I have inserted a button in an Excel xls-File which invokes a Visual-Basic routine.
how can I invoke this routine cmdButton_Click() with ole?

best regards, Norbert
User avatar
NK
 
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany

Postby Jeff Barnes » Thu Oct 05, 2006 12:59 pm

Norbert,

I don't know if this will help but you can try to record a macro, then click your button. Now edit the macro and look at the code, it might give you an idea as to how to incoke from FW.

Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby NK » Thu Oct 05, 2006 1:23 pm

Jeff,

Jeff Barnes wrote:Norbert,

I don't know if this will help but you can try to record a macro, then click your button. Now edit the macro and look at the code, it might give you an idea as to how to incoke from FW.

Jeff


good idea but the click on the button isn't recorded in the Macro.

Norbert
User avatar
NK
 
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany

Postby Gale FORd » Thu Oct 05, 2006 1:32 pm

Try recording a macro.
Then record another macro that runs the first macro.
Then debug code and you will find something like
Application.Run "Book1!Macro1"

Maybe this gives you a clue.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby NK » Thu Oct 05, 2006 1:53 pm

Gale FORd wrote:Try recording a macro.
Then record another macro that runs the first macro.
Then debug code and you will find something like
Application.Run "Book1!Macro1"

Maybe this gives you a clue.


Unfortunately, this doesn't work either since the keystroke isn't recorded in the macro.

I would like simply to fill a table with values and then reprocess these data by a routine which I have put on a key.
Code: Select all  Expand view
Private Sub cmdCreateBeleg_Click()

    If (bOLAnmeldung) Then
        'MsgBox "Anmeldung erfolgreich"
        bAngemeldet = True
    End If
    ReadCells
    If bAngemeldet Then
        bOk = bSetBelegKopf
        bOk = bSetPositionen
        bOk = bSaveBeleg
        WriteErgebnis
    Else
'         MsgBox "Sie sind nicht an der Office Line angemeldet."
    End If

    Clear

End Sub


Isn't it possible to start a Visual-BASIC routine with OLE, then?

Norbert
User avatar
NK
 
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany

Postby Gale FORd » Thu Oct 05, 2006 2:09 pm

Why not put the code that is now in cmdCreateBeleg_Click() in a macro.
Then call the macro from cmdCreateBeleg_Click(), and from external program.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby NK » Thu Oct 05, 2006 2:25 pm

Gale FORd wrote:Why not put the code that is now in cmdCreateBeleg_Click() in a macro.
Then call the macro from cmdCreateBeleg_Click(), and from external program.


Because within this routine further Functionen are invoked.
I have tested it. An error message "Function or Sub not defined" then comes

Norbert
User avatar
NK
 
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany

Postby NK » Thu Oct 05, 2006 2:35 pm

Gale FORd wrote:Why not put the code that is now in cmdCreateBeleg_Click() in a macro.
Then call the macro from cmdCreateBeleg_Click(), and from external program.


I have worked to execute the routine as Macro (simple this Private remove).
Can you still give me a tip as I start a Macro with OLE?

Norbert
User avatar
NK
 
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany

Postby Gale FORd » Thu Oct 05, 2006 2:56 pm

This works for me.
Code: Select all  Expand view
function test()
   oExcel := TOleAuto():New("Excel.Application")
   oExcel:WorkBooks:Open( "H:\My Documents\test.xls" )
   oExcel:Visible := .t.
   oExcel:Run( "test.xls!Sheet1.CommandButton1_Click" )
return( .t. )
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Gale FORd » Thu Oct 05, 2006 2:58 pm

Here is the code for my button in sheet1
Code: Select all  Expand view
Sub CommandButton1_Click()
  MsgBox "Sie sind nicht an der Office Line angemeldet."
End Sub
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby NK » Thu Oct 05, 2006 4:23 pm

Gale FORd wrote:This works for me.
Code: Select all  Expand view
function test()
   oExcel := TOleAuto():New("Excel.Application")
   oExcel:WorkBooks:Open( "H:\My Documents\test.xls" )
   oExcel:Visible := .t.
   oExcel:Run( "test.xls!Sheet1.CommandButton1_Click" )
return( .t. )


It works. Many thanks to you.

Norbert
User avatar
NK
 
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 84 guests