Displaying Excel Userform without opening file - excel

I have created a Userform, currently I am using this code to hide Excel and just show the userform (Code was place in Workbook)
Private Sub Workbook_Open()
Application.Visible = False
ricwin.Show
End Sub
The issue I am facing is that in ocassions the excel file will open but not as macro enable, and I require to close it and reopen it so the macro runs.
Also is there a chance to display a taskbar icon for the userform without an excel file being in background?

You can fix the problem by adding a ToggleButton to the userform. When the workbook is opened, the worksheet is hidden, only the userform is shown. For this, the following codes are added to a module:
Sub Auto_Open()
Application.Visible = False
UserForm1.Show
UserForm1.ToggleButton1.Value = False
End Sub
enter image description here
Source of sample file

Related

Why macros are disabled each time I re-start my Excel workbook, even after enabling content...?

Here the context : I'm working on a local workbook (c:) that directly opens a UserForm within the Workbook_Open() Sub. Then, when UserForm is closed, Excel is also automatically closed. Nothing special there.
The problem : Even with a correct setup in my Trust Center Settings (Disable all macros WITH notification), the warning security message pops up again each time I reload that workbook.
Here my code :
Private Sub Workbook_Open()
' modal display of my form
myUserForm.Show vbModal
' upon return from my form, save and close that workbook
Me.Close savechanges:=True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' also quit Excel app if no more workbook is opened
If Application.Workbooks.Count = 1 Then Application.Quit
End Sub
I'm pretty sure that's related to the fact that Excel is automatically closed by program, and not by user himself.
For example if I reduce the code to the strict minimum, like :
Private Sub Workbook_Open()
myUserForm.Show vbModal ' modal display of my form
End Sub
In that situation, so without any Close or Quit, I just fall into my main worksheet when the UserForm is closed, then I just manually close Excel, with or without saving, and that's it, warning popup will not appear next time I'll open that workbook.
I don't know if there is a solution without playing with Trust Locations or All macros enabled.
Any ideas ?
Thanks for your help

How to hide ribbon with on event macro in excel?

I have been trying to hide a ribbon automatically when opening the workbook with this code
Private Sub Workbook_Open()
Application.CommandBars.ExecuteMso "HideRibbon"
End Sub
It is not working as on-event open workbook but it is working when i press F5, any advice?
'

Excel VB - insivible work sheet

I want to open only the userform when I open the excel sheet. I used the below code but other excel also become invisible. I want to display other open excel file and only macro contained file should be disable.
Application.Visible = False
UserForm4.Show
If I see well what you mean, I think the best thing to do is to make your xlsm file an add-in. In order to do this:
1) Call the UserForm4.Show into the Workbook_Open event of your .xlsm;
2) Save your workbook as Excel Add-In (extensions: .xla or the newer .xlam);
3) Enable the add-in on Excel, so every time that a workbook is opened you can show the form and not the entire workbook, so avoiding also to let the EXCEL.EXE instance open (that will remain so if the Application is Visible=False, because no user would see it after closing the workbook they're working with).
Add-ins have a great power in terms of use and distribution, I suggest you to get started from here and go deeper into this very nice tool.
Add the following code to the user form...
Private Sub UserForm_Initialize()
ThisWorkbook.Windows(1).Visible = False
End Sub
Private Sub UserForm_Terminate()
ThisWorkbook.Windows(1).Visible = True
End Sub

Closing Excel UserForm on CommandButton click

I have a sheet that has a ListBox. The sheet code has a ListBox_DblClick sub that launches UserForm1. UserForm1.CommandButton1 launches UserForm2. The user may input data in UserForm2 then press UserForm2.CommandButton1 which launches a sub in a module (yet to be written) and closes UserForm2.
With the code below, both UserForm2 and UserForm1 close. I just want UserForm2 to close upon click of UserForm2.CommandButton1.
Any thoughts on what I'm doing wrong are appreciated.
UserForm2 code
Private Sub CommandButton1_Click()
Call UpdateBids(TextBox1.Object.Value, TextBox2.Object.Value, ComboBox1.Object.Value)
Unload Me
End Sub
Upon researching this again, I stumbled upon this post:
Why, after launching a userform from a userform, does unloading the 2nd userform close both?
In short it suggested closing Excel then adding DoEvents following UserForm2.Show. It worked. Now only my UserForm2 closes. I've not had the problem since.

Attach Existing UserForm Button to Excel Workbook Sheet

I have an Excel workbook that has a macro (the only macro in the workbook) attached to a button on a sheet.
In VB mode, I created a UserForm under Forms with a CommandButton1_Click Sub and when run from within VB (Run > Run Sub/UserForm or F5) it runs fine. I have it calling a Shell command that runs a BAT file that runs a Python script.
How do I run CommandButton1_Click from a button on a sheet? If I try to add a button to a sheet, it offers me the macro I have already associated with the other button.
Create one macro for example
Sub ShowForm
YourForm.show
End Sub
And associate this macro in button.
Why don't you move the main code into a new macro to modularise it. You can then call your macro via both UserForm and worksheet ActiveX (or Forms) buttons
'Normal Code Module
Sub TestCode()
MsgBox "Hi"
End Sub
'UserForm code
Private Sub CommandButton1_Click()
Call TestCode
End Sub
'ActiveX button code
Private Sub CommandButton1_Click()
Call TestCode
End Sub

Resources