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
Related
I was just creating a template on Word which uses content controls and I have a userform to help auto fill the data which is activated via a command key. You know how on excel VBA you can click a cell to make it refresh or open up a userform, or perform a series of tasks. On Word, can you double or single click a Content Control per say and have a userform pop up?
I think it would be pretty neat to be able to do that, open for any ideas that I should try out.
Unlike Content Controls, ActiveX controls have Click and DoubleClick events. You can add an ActiveX control (e.g., a button or a label) and use its Click event to do whatever you want:
And then simply, use something like this:
Private Sub lblTest_Click()
MsgBox "You clicked on a label."
End Sub
Private Sub btnTest_Click()
MsgBox "You clicked on a button."
End Sub
Result:
Hope that helps.
I hope you can help me with this issue, I couldn't find any answer nor on google nor here. So here's the point:
I have to userforms. One of them opens on Worksheet_Open. In the Background I can still see the worksheet and the excel application. But when I click outside of the userform or close it, the application window disapears too. But in the open processes I can still see excel open.
My intention is to have the Excel window always open (in the background) so that when I close the UserForm the Excel Tables will be visible.
What do I have to code for that? To hide the userform didn't work for me...
Thanks in advance.
Hi there if you want to use both excel and your Userform at the same time then go to your Userform property and make ShowModal = False
I am not very good with userforms so hopefully this is an easy question.
I have a userform in a spreadsheet that opens with
UserForm1.Show False
To ensure excel can still be used while it is open. What I would like to happen is that whenever you click away from (but not close) the userform a text box is opened asking if you want to maintain the edited values or not. I can't figure out how to initiate more code when the userform is no long the point of interest. Usually items on userforms have enter and exit which I believe would do what I need but I can't find the equivalent for the actual userform.
Any advice would be appreciated.
To allow a user to enter values into excel while a form is visible, you will need to update the ShowModal property on the userform to false.
Or as you are showing the userform, you can show it vbModeless.
UserForm.Show vbModeless
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.
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/