FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour call visual-basic routin in an excel .xls
Posts: 97
Joined: Sun Nov 20, 2005 04:32 PM
call visual-basic routin in an excel .xls
Posted: 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

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
call visual-basic routin in an excel .xls
Posted: 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

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 97
Joined: Sun Nov 20, 2005 04:32 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 01: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
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 01: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.

Posts: 97
Joined: Sun Nov 20, 2005 04:32 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 01: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.
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
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 02: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.

Posts: 97
Joined: Sun Nov 20, 2005 04:32 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 02: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
Posts: 97
Joined: Sun Nov 20, 2005 04:32 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 02: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
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 02:56 PM
This works for me.
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. )
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 02:58 PM
Here is the code for my button in sheet1
Sub CommandButton1_Click()
  MsgBox "Sie sind nicht an der Office Line angemeldet."
End Sub
Posts: 97
Joined: Sun Nov 20, 2005 04:32 PM
call visual-basic routin in an excel .xls
Posted: Thu Oct 05, 2006 04:23 PM
Gale FORd wrote:This works for me.
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

Continue the discussion