Pushing Button Programatically

brodie24
03-11-2004, 10:25 AM
I have a pre-existing form in Excel which has several buttons, I would like to be able to push those button, through my ASp.Net application. I have already learned how to populate fields,etc... But, now I need to figure this out.

ANy help would be very nice!
Erich

herilane
03-11-2004, 10:49 AM
I assume the buttons call a VBA macro?
How are you populating the fields?

brodie24
03-11-2004, 07:20 PM
I assume the buttons call a VBA macro?
How are you populating the fields?

Yes, it activates a VBA macro.
I am populating fields with commands shuch as:

oSheet.Range("G14") = value

Where oSheet is a Excel worksheet object.

herilane
03-12-2004, 05:06 AM
Try this: Make the commandbutton's Click event Public instead of Private, and then call the macro directly, as if it were a normal sub:
oExcelApp.Run(oSheet.Name & ".CommandButton1_Click")

brodie24
03-12-2004, 09:32 AM
Try this: Make the commandbutton's Click event Public instead of Private, and then call the macro directly, as if it were a normal sub:
oExcelApp.Run(oSheet.Name & ".CommandButton1_Click")

I placed the marco's modifier public, then when I try and run it, it give me an error which says:
The macro 'Year1.InsertPI()' cannot be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The macro 'Year1.InsertPI' cannot be found.

herilane
03-12-2004, 11:00 AM
Right... so where's the macro, and what's its name?
I assumed the button was an ActiveX control with a _Click event procedure, but it sounds like we have something different on our hands here. Is this a Forms toolbar button?

brodie24
03-12-2004, 12:10 PM
Right... so where's the macro, and what's its name?
I assumed the button was an ActiveX control with a _Click event procedure, but it sounds like we have something different on our hands here. Is this a Forms toolbar button?

Here I put it here so you can download it, instead of me trying to explain it. I'm new at this automation and macro stuff.

http://www.finite-state.com/test/FastLane.xlt

Can you take a look please?

brodie24
03-12-2004, 12:33 PM
Here I put it here so you can download it, instead of me trying to explain it. I'm new at this automation and macro stuff.

http://www.finite-state.com/test/FastLane.xlt

Can you take a look please?

OK, it didn't like the oSheet prefix. I took it out and just put the name of the marco and it works.

Thanks for all of your help!

Mike Rosenblum
03-12-2004, 12:38 PM
Ok, yes, that "Button" is from the Toolbar named "Forms". The type that Herilane was originally assuming was that it was a CommandButton from the Toolbar named "Controls Toolbox".

In this case you would want to call oExcelApp.Run("'FastLane.xls'!InsertPI") which is the same command that your Button is calling (via its OnAction property).

:),
Mike

brodie24
03-12-2004, 12:52 PM
If you guys that are helping me with the excel buttons have noticed, when you hit the Add New Year, it pops up with a dialog box asking how many years. How can I just press OK, and accept the default value?

brodie24
03-12-2004, 12:54 PM
Thanks!

Mike Rosenblum
03-12-2004, 01:58 PM
Personally, I would make a new routine, similar to your Sub NewBudgetYears() routine, but one that omits the line

YearsToAdd = InputBox("Enter number of years to add", "", 1)

and simply make it read

YearsToAdd = 1

Instead.

Maybe call this routine Sub NewBudgetYears_AddOne() or something? Then call this new routine as needed using oExcelApp.Run().

-- Mike

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum