Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: VB  (Read 2697 times)

0 Members and 1 Guest are viewing this topic.

alex1991

  • Guest
VB
« on: February 20, 2008, 05:06:41 AM »
Does anyone know how to apply a macro to a button on a userform in Microsoft Excel using VB?  Response needed within the next 24 hours if possible.
« Last Edit: February 21, 2008, 05:36:42 AM by alex1991 »

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: VBA
« Reply #1 on: February 20, 2008, 08:34:08 AM »
Does anyone know how to apply a macro to a button on a userform in Microsoft Excel using VBA?

At first I thought this was a Yes or No question. ;D

When you double click your button in design view, the VB Editor will pop up. Write your macro within the Sub/End Sub statements already provided. This is the click event for the button.

This works for any control on the form, including the form itself. The default is the click event (upper right hand corner) but you can change it as needed.

 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

alex1991

  • Guest
Re: VBA
« Reply #2 on: February 21, 2008, 03:49:57 AM »
Thanks, but if I wanted to make a button called Quote run a macro of the same name, what code would I need to type in?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: VBA
« Reply #3 on: February 21, 2008, 06:02:32 AM »
Are you drawing this button on the worksheet? Or do you want to attach a macro to a toolbar button?

For the former, the original response will work. Draw the button. You can right click the control to change properties such as the caption, name, etc. When you double click the button the VB Editor will appear and you can write your code. Once written you can use Tools-->Macro-->Macros to edit or even assign a shortcut key sequence (options button)

For the latter, go to Tools-->Macro-->Visual Basic Editor. In the left pane either double click the sheet name (local to the sheet) or thisworkbook (local to the workbook). Again the Visual Basic Editor will appear and you can write your code. Attaching the code to a button is more problematic. I suggest you use the help and search for "Add a button" for a detailed description.

Hope this helps.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

alex1991

  • Guest
Re: VB
« Reply #4 on: February 22, 2008, 03:52:37 AM »
Thanks, the buttons are working now.  Much aprreciated.

alex1991

  • Guest
Re: VB
« Reply #5 on: February 25, 2008, 03:50:09 AM »
Found a different way to make the buttons work.  If you copy the code from the macros into the code for the buttons then the buttons will perform all of the functions that the macro does.