I have this vba code where it has a userform.
Now I would like to start the userform; where the people can't see the Worksheets.
I have added this in my code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Application.Visible = True
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True End Sub
Then in the "ThisWorkbook; I have added this:
Private Sub Workbook_Open()
Application.Visible = False ' only for final version
UserForm1.Show
'enter code here
End Sub
The thing is when I upload this .xlsm to a website, and when you open it; it does not start the userform right away. It somehow goes to an error. If you have an excel open.
Not sure how to protect the file, without having the endusers altering the file
Any ideas?
Maybe this helps:
In "ThisWorkbook" under "Open" add:
Private Sub Workbook_Open()
Application.Visible = False
UserForm2.Show vbModeless
End Sub
This will hide Excel and execute UserForm2.
BTW: To end your program add this code (e.g. to one of your Userform Buttons):
Private Sub CommandButton1_Click()
Application.Quit
End Sub
It will close Excel.
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
Could you please help to solve the problem I am facing,when i run the program its throwing me an error "Object dosen't support this property or method"
Private Sub Workbook_Open()
'Application.Visible = False
'Application.ScreenUpdating = False
Windows("ETY Tracker V1.2.xlsm").ScreenUpdating = False
UserForm1.Show
End Sub
please help...I also tried both application .visible but it will close all the active workbooks we have, and application.screenupdating will not allow me to edit or open any other sheet other than the present user form.
Are you trying to hide the workbook and just show the form?
Private Sub Workbook_Open()
ThisWorkbook.Windows(1).Visible = False
UserForm1.Show
End Sub
Or hide Excel and show the form? This won't close the workbooks - they're just inside the application which in itself is hidden.
Private Sub Workbook_Open()
Application.Visible = False
UserForm1.Show
End Sub
Excel.Application.ScreenUpdating doesn't stop users from interacting with Excel, it just stops them from seeing the interaction.
Try Application.Interactive = False, but remember to set it back to true or you will have to close your excel application.
I have a userform with 2 command buttons : hide and show.
This work if I only have 1 workbook open. I can simply hide and show the workbook from the form. However If I have another workbook open let say Book1. and then I click Hide, It will also hide the Book1. I want only to hide the specific workbook.
Here's my code:
Private Sub cmdHide_Click()
'ThisWorkbook("hide_sheet").
Application.Visible = False
End Sub
Private Sub cmdShow_Click()
'ThisWorkbook("hide_sheet").
Application.Visible = True
End Sub
Should be something like this
Option Explicit
Private Sub cmdHide_Click()
'ThisWorkbook("hide_sheet").
Workbooks("Book1.xlsx").Windows(1).Visible = False
End Sub
Private Sub cmdShow_Click()
'ThisWorkbook("hide_sheet").
Workbooks("Book1.xlsx").Windows(1).Visible = True
End Sub
Another Example that work on both Excel 2010 & 2013
Option Explicit
Private Sub cmdHide_Click()
'ThisWorkbook("hide_sheet").
Windows(ThisWorkbook.Name).Visible = False
End Sub
Private Sub cmdShow_Click()
'ThisWorkbook("hide_sheet").
Windows(ThisWorkbook.Name).Visible = True
End Sub
I have made a User form in Excel, so when i open the xlsm-file it only opens the user form, and the workbook is hidden.
But when i close the user form with the [X]-button I want it to close both the workbook and the user form without saving.
When I close the user form now, and try to open the same file again, it says that it is already/stil open.
Start up code:
Private Sub Workbook_Open()
Application.Visible = False
Fordelinger.Show vbModeless
End Sub
Close code:
Private Sub Fordelinger_Deactivate()
Application.Quit
Workbooks("EstimatDOK.xlsm").Close True
End Sub
Can anyone help? :)
may be you wanted this code in the UserForm code pane
Private Sub UserForm_Terminate()
ThisWorkbook.Close
End Sub
you can use the below code to restrict close (X) button
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
MsgBox "The X is disabled, please use a button on the form to Exit.", vbCritical
End If
End Sub
or
Private Sub UserForm_Terminate()
ThisWorkbook.Close savechanges:=False
Application.Quit
End Sub