Excel macro - open macro without going into Visual Basic? - vba

I've finished my macro! But is there an easier way in runnning it?
I know two ways
Open Visual Basic, select the correct macro and run!
View Macro's, select the correct macro and run!
Is there an easier way, or are these the only two ways?
Thanks

Place a command button on your sheet, view its code in the VB editor, and edit it so it looks something like this:
Private Sub CommandButton1_Click()
Call MyMacro
End Sub
You can then just click your button every time you want to run your macro.

you can even create little smiley icon in your Toolbar so that it stays there and you can run it by clicking it or have shortcut keys attached to it.

There are several options:
Toolbar or Menu (Excel 2003 & earlier)
http://peltiertech.com/WordPress/how-to-assign-a-macro-to-a-toolbar-or-menu/
ActiveX control
http://peltiertech.com/WordPress/how-to-assign-a-macro-to-an-activex-control/
Button (Forms menu control) or Shape
http://peltiertech.com/WordPress/how-to-assign-a-macro-to-a-button-or-shape/

Related

excel not responding after closing Find menu that is opened with vba

I have created a button in a excel sheet that opens the Find menu (ctrl+f).
Sub Button6_Click()
Application.Dialogs(xlDialogFormulaFind).Show
End Sub
After the search is done and one closes this menu excel doesn't respond anymore and closes itself. Any ideas why?
Also, I don't get the exact same find dialog as when I use ctrl+f. Is there maybe a way to use keyboard-functions in vba?
Why not use ctrl+f instead of the button. Because my colleagues are not quite good with excel and that already is too much to remember for them :)
This is how to mimic a key press in VBA ^ is Ctrl
Sub Button6_Click()
Application.SendKeys ("^f")
End Sub

Progress Bar in Excel using VBA and userForms

so I've been looking and cant find anything on this, I hope someone can help.
what I am trying to do:
I want to create a progress bar for my excel workbook that I am making. in order to accomplish this I have created a user form with data fields that I can manipulate from outside of the userform. what I would like to do is to load the userform from inside a module and then from the same module update the userform as the module continues to run.
is there a way to do this?
currently when I use userForm1.Show it displays the userform, but the control never goes back to the calling module, and the code ends when reaching the End Sub for Private Sub userForm1_Activate()
any help would be appreciated.
thank you
You are opening the userform as a modal form. To return the control back to the calling module, you must open the userform modelessly:
UserForm1.Show vbModeless

View Code When Modal Dialog Is Open In Excel

This may be a stupid question, but I feel like I'm in a pickle. I have a modal UserForm that opens when an Excel workbook is opened. When the UserForm is closed, the Excel workbook is saved and closed. I need to be able to view my code, but I can't seem to figure out how to do that because if I close the modal dialog box, the workbook closes. Does anyone know how I can view my code? I really apologize if this is a stupid question, but I can't seem to figure it out.
Thanks for you time and effort.
Without restarting the workbook i.e when the userform is shown in modal, you can use CTRL + Shift + Pause/Break to get into the VBE
Depending on laptops the key combination might change. Here is another which you can try.
Fn + Pause/Break
Hold the shift key when opening the workbook. This allows you to open office applications with macros not running and can be useful in situations like this.
Then view the macros (hit Alt+F11 to open it this editor).
The two other suggestions are good. For easiest debugging, I'd put the code that opens the userform in a separate routine and then call that routine from Workbook_Open. That way you can run and debug your code without having to re-open the workbook.
Then your ThisWorkbook module might look something like this:
Private Sub Workbook_Open()
MyUserformProcedure
End Sub
Sub MyUserformProcedure()
UserForm1.Show
End Sub
You could then comment out the line in Workbook_Open and call MyUserformProcedure, and uncomment the line when you're finished debugging.

Creating Strikethrough Macro in Excel

I'm a novice to VBA and I'm trying to make a simple macro where one can highlight a set of cells, click a button, and strikethrough the selected sells. After, you can select the cell again, click the same button, and remove the strikethrough.
I have been looking for decent documentation but, have yet to find anything.
Here's some code.
Also, I would love to know where the best documentation is on VBA.
Sub strikeOut()
Selection.Font.Strikethrough = True
End Sub
I also need help with the command button.
Thank you.
It looks like you're on the right path. Based on your code, I'm assuming you already have a command button created. If so try this:
Sub strikeOut()
With Selection.Font
.Strikethrough = Not .Strikethrough
End With
End Sub
To create a command button:
Excel 2003 and earlier:
Open up the Visual Basic toolbar and activate the Control Toolbox button. Another box/toolbar should appear with different control options.
Select the Button option and place it in the desired location.
Excel 2007 and later:
Click on the Developer tab/ribbon.
Select Insert and select Button and place it in the desired location.
*The steps below apply to all versions from this point forward.
Right-click on your new button and select Properties to give your button a name/caption.
Right-click again and select View Code.
In the ButtonName_Click() sub, add the strikeOut() call using either:
Call strikeOut()
or simply
strikeOut
To answer the second part of your question, it's hard to say what is the 'best' but here are some links that may help:
Chip Pearson's site
MSDN
OZgrid

In Excel, is there a way to determine the method being called by a password protected 3rd-party ribbon button?

I'm looking to automate a simple process in VBA and need to "click" a ribbon button. It makes the most sense to just call the button's underlying method. Is there a way to figure out what it is?
We are using Excel 2007 and 2010.
If it's Excel 2003 or earlier, you can use the CommandbarControl.Execute method. For instance:
Application.Commandbars("3rd Party Toolbar").Controls("Button to Push").Execute
There are two ways you can do this.
Right click on the toolbar and select Customise. If you right click on the button there may be details somewhere of what Macro the button is associated with.
If you record a macro and click the button. Then you can look at the VBA workspace and view the code that is generated to run your macro (which is just clicking the button you want). This will show you what method the macro clicks.