• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Attach a macro to my existing Excel code

 
Ranch Hand
Posts: 949
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have Excel VBA performing what I want it do do very nicely.

It has one UserForm with a run button on it.  The user presses the button and it does what it is supposed to.

I only know how to start the whole thing by using Alt + F11.  

I want to start it from the menu bar where the Macros be launched.

What I don't know is where is the starting point of the whole thing?  How do I name the macro?  What should it call?

Thanks,

Kevin  
 
Saloon Keeper
Posts: 28313
207
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it still "VBA" in a .Net era?

I have not worked with Excel in over a decade, but I thought that there was a menu that allowed you to create, edit, and run macros. Though it's possible that it's no longer obvious. I hated the ribbonbar Office apps when the "Print" button disappeared.
 
kevin Abel
Ranch Hand
Posts: 949
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
I appreciate the reply.  

I know how to record a macro.  It shows up in the list of macros.  It calls the single recorded macro.

I already created code it consists of a userform with two buttons on it. .

One sub is for the user form.  Then one ach for the buttons.

In Java speak the button subs remind me of listeners. I don't know where public static void  main () equivalent is.  

I don't know if I should be adding a sub to the user Format.

Thanks,

Kevin
 
kevin Abel
Ranch Hand
Posts: 949
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should say userForm at the end of the last post.
 
Tim Holloway
Saloon Keeper
Posts: 28313
207
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's like asking where the public statis void main() is in a webapp.

There isn't any.

Generally, you'd attach a macro to a button. But you can also attach one to the "onload" event that should be firing when you open that sheet or workbook if that makes more sense.

Don't do anything long-running if you do that though, or people will think the spreadsheet is broken.
 
kevin Abel
Ranch Hand
Posts: 949
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,

I received a reply on MrExcel.com from a member named NateSC.  I tried it and it  works. The trick was to put the sub inside of the userForm.  This was the reply:

Do you have all of the macros inside the UserForm? If so, then you need a macro either in a Sheet or a Module that you can run from the Macro - Run button. For example, you can go into the VBA editor, select "ThisWorkbook" in the Project window, and then add a new sub (i.e. Sub myStart())
Inside your initial Sub, you might do some stuff and then you would Load your UserForm and then Show your UserForm.
VBA Code:
Sub myStart()
'Do some stuff here
Load UserForm1
'You can do more stuff here to modify the form if needed before making it visible
UserForm1.Show
End Sub
I'm not sure how your Sub Sheet_To_Param_Data() interfaces with the UserForm. The way they interact will determine how you Call/launch that Sub.
 
You get good luck from rubbing the belly of a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic