I have a userform which I cannot select in the quick access toolbar to add to the ribbon.
All of the other macros I have are visible and can be selected to be added to the quick access toolbar.
I have the name of the userform and command buttons in the userform code matching the name listed within their reposective properties windows.
I have been able to add userforms to previous versions of excel so I am not sure if anything has changed for excel 2016.
Sub userform1_show()
UserForm1.Show
End Sub
Private Sub CommandButton1_Click()
Load.Linux_unix_scan_tab_only
Linux_unix_scan_tab_only.Linux_unix_scan_tab_only
End
End Sub
Private Sub CommandButton2_Click()
Load.unix_SSHkey_tabs
unix_SSHkey_tabs.Linux_unix_scan_and_SSH_Key_trust_tabs
End Sub
Private Sub userform_click()
End Sub
Related
I created a simple userform for testing, but one issue comes up and i have no idea how to resolve it.
This is the case:
When I open .xlsm file for the first time and close the userform and workbook, this closes both of them.
But when I continue to click the .xlsm file again, close the userform and the workbook, it (the userform) pops up again.
It seems the workbook doesn't close.
Then i need to close the userform again to close this workbook.
I would like help to understand why the userform comes up again?
The userform only has one listbox controls.
The following code is in a module:
Private Sub Auto_Open()
UserForm1.Show
MsgBox "Close2"
ThisWorkbook.Close
End Sub
The userform contains the following code:
Private Sub UserForm_Initialize()
Application.Visible = False
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
MsgBox "Close1"
End Sub
You could try to put this into the workbook code section as followed.
And not put it in a separate module.
Private Sub Workbook_Open()
Application.Visible = False
userform1.Show
MsgBox "Close2"
ThisWorkbook.Close
End Sub
you can remove the code for the user form initialize.
The thing is as its hidden you might open it twice cause you do cause it does not respond directly.
Is it possible to get the same effect using ThisWorkbook.Application.Visible = False but only for one Workbook. I mean, I'd like to limiting user interaction only to UserForm, but I need have an access to anothers workbooks. At the moment this function cause hide workbook, but after open some another excel file - all object from userform are not available.
Private Sub Workbook_Open()
ThisWorkbook.Application.Visible = False
Starter.Show modeless
End Sub
Thanks for your support.
Please, create a form, let us say "Starter", having (at least) a button ("btExit"), copy the next code in its code module and show it. If the form in discussion already has some code in Initialize and Terminate events, please add the next code lines, too:
Option Explicit
Private Sub btExit_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
ThisWorkbook.Windows(1).Visible = False
End Sub
Private Sub UserForm_Terminate()
ThisWorkbook.Windows(1).Visible = True
End Sub
So, you can simple use workbook Open event in this way:
Private Sub Workbook_Open()
Starter.Show vbModeless
End Sub
Using App_DocumentBeforeSave (in Class1), and Document_New with Call Register_Event_Handler in ThisDocument, I cannot use my usual code to open up a Userform (Autoopen, AutoNew).
How should I place code to allow both DocumentBeforeSave code as well as Userform initiation code?
Sorry for not being more clear. In the template with the working code for changes to a document BeforeSave:
In Microsoft Word Project ThisDocument:
Private Sub Document_Open()
Call Register_Event_Handler
End Sub
Private Sub Document_New()
Call Register_Event_Handler
End Sub
In Modules, Module1:
Dim X As New Class1
Public Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub
In Class Modules, Class1:
Public WithEvents App As Word.Application
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
‘
‘ Then follows my clean up code in this Sub, which also Calls Subs, which are also placed in Class1 under this Sub.
All this works as intended. However, I wrote the code above for all of the Templates we use to generate medical reports, many of which also bring up UserForms upon opening. However, all my templates with UserForms have this code in In Microsoft Word Project ThisDocument to open the Userform whenever the document or template opens:
Sub Autoopen()
Options.ButtonFieldClicks = 1
MACROS.Show
With MACROS
.Top = Application.Top
.LEFT = Application.LEFT
End With
End Sub
Private Sub Document_New()
Options.ButtonFieldClicks = 1
MACROS.Show
With MACROS
.Top = Application.Top
.LEFT = Application.LEFT
End With
End Sub
I cannot get the Userform opening code to work with the initializing code for the DocumentBeforeSave – for one thing they both use Sub Document_New(). I tried changing the Userform opening code to Sub AutoNew(), which still didn’t function.
The Userforms without the DocumentBeforeSave code open fine, and the DocumentBeforeSave code works OK without the Userform code. How do I get both to work in the same project? BTW - the error that occurs: it won't save the project/document.
Thank you.
AutoOpen, AutoNew and AutoSave belong in a "plain vanilla" module. It looks like you've tried putting them in a class, which won't work...
When a workbook has many sheets such as 100, you can activate the sheet quickly by right-clicking the arrows on the bottom left and then a prompts shows up by lets you choose which sheet you want to select. However, I want to be able to reach this prompt without clicking and using just the keyboard. So I want to create a simple macro where I can quickly pull up this prompt by assigning to something like ctrl+g. However, I do not know how to do this in vba.
Build your replica Activate form: Insert a userform into your project. Set its caption to "Activate". Add a label to it that says "Activate:". Add a Listbox and two buttons. Label one button Ok and the other Cancel.
In the UserForm_Initialize sub of the userform, Loop through the names of your sheets and add them to the listbox....something like:
Private Sub UserForm_Initialize()
Dim oSheet As Worksheet
For Each oSheet In Worksheets
ListBox1.AddItem oSheet.Name
Next
End Sub
Private Sub CommandButton1_Click()
Sheets(ListBox1.Text).Activate
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Now in the ThisWorkbook section of the VBA Project, add a sub to show your userform:
Private Sub ShowActivateForm()
UserForm1.Show
End Sub
Go back to Excel and click the Macros button on the developer tab. You should see a macro named ShowActivateForm. Select it and click Options to assign it your desired hotkey.
I kept a userform control button in my worksheet to fire up a macro, which in turn shows a user form, In the form I wish to display the opened files in checkboxes(using the Workbooks collection).I wish to run a macro that performs action for the user selected files only.
So for the button in my worksheet, I have assigned the following macro
Private Sub Button2_Click()
Load MyForm
MyForm.Show
End Sub
At first I kept the below code in the module where my macro sub is there.Since it's not working, I right clicked on user form and selected view code and kept the below code there.But still it's showing the same static designed user form, not the dynamic.I kept breakpoint at both load Myform and MYform.Show() and I stepped through code.It never went into intialize or activate method at all.
Private Sub MyForm_Activate()
'for checking the whether this method is called or not I am trying to change caption
MyForm.LabelSelectFile.Caption = "dhfdfldkfldzjf;zdfkz;d"
Dim mymyWorkBook As Workbook
For Each mymyWorkBook In Workbooks
'code for creating checkbox based on the file name displayed by the workbook collection
Next mymyWorkBook
End Sub
I can't understand why that event is not getting triggered.Please help me to overcome this.Thanks in advance
Even though the name of the form is MyForm, you still need to use userform.
'~~> in your worksheet
Private Sub Button2_Click()
MyForm.Show
End Sub
'~~> In the userform code area
Private Sub UserForm_Initialize()
'~~> Your code here
End Sub
or
Private Sub UserForm_Activate()
End Sub
The best is to always select the event from the drop down, rather than typing it