Unload Control Panel and Load another Userform

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
788
Office Version
  1. 2010
Platform
  1. Windows
Hi guys, bashing my head against a wall here.


Here's how I load my Control Panel Userform from a button on my sheet:

VBA Code:
Sub CPanel_Click()

Load CPanel
CPanel.Show

End Sub
VBA Code:
Private Sub Userform_Initialize()

Me.StartUpPosition = 0
Dim Top As Double, Left As Double
Top = Abs(Application.Top) + _
(Application.Height - ActiveWindow.Height) + _
(Application.UsableHeight - ActiveWindow.UsableHeight)
Left = Abs(Application.Left) + ActiveWindow.Width - ActiveWindow.UsableWidth
Me.Top = Top
Me.Left = Left

End Sub


On this Control Panel Userform are many buttons, one of them is supposed to load an Import Panel, unloading the Control Panel in the process:

VBA Code:
Private Sub ImportPanel_Click()

Call Userforms.ImportOpen

End Sub

Sub ImportOpen()

Load ImportPanel

End Sub


For some reason, this isn't doing anything, but before it was saying "Compile Error: expected function or variable" which isn't that helpful to me.

Any ideas? Cheers.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What if you try simply ImportOpen or Call ImportOpen
VBA Code:
Private Sub ImportPanel_Click()

    Call ImportOpen

End Sub
 
Upvote 0
Hi Norie, this just does nothing - the module is called and when I get to the line "Load ImportPanel" nothing happens.

Also, my VBA window has gone weird - the project and properties window have stretched across the entire Visual Basic window, and the actual code is squashed underneath, and I can't seem to resize or dock the Project or Properties windows.
 
Upvote 0
Load does not show a form, it merely loads it (as in your original button)
 
Upvote 0
Hi Rory,

If I double click the "Import" button I go straight to the code for loading the panel:

VBA Code:
Private Sub ImportPanel_Click()

Load ImportPanel


End Sub

If I run this code, when I get to "Load ImportPanel" it says "Run Time Error 361 - can't load or unload this object"

Also adding a ImportPanel.show line gives an error too.
 
Upvote 0
I've changed the name of the macro to not be the same as the UserForm. So there's one "ImportPanel" now in my sheet and it's the Userform. The Macro inside the button that calls the import panel to load is now called "imp_button"

Now when I do "ImportPanel.Show" it loads - because it's not trying to "show" a macro, it's showing ImportPanel which is now only ever going to be a Userform.

Once again fantastic Excel and VBA error messaging to the rescue.

Is Excel 365 any more verbose with the VBA error messaging or is it largely unchanged?
 
Upvote 0
VBA hasn't really changed a lot in the last 20 years.
 
Upvote 0
I know it's not the preferred language to write code in, but it's pretty widespread, I wonder why they can't try and make it more user friendly like other languages.
 
Upvote 0
It's not part of their future roadmap so they won't invest in it.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,533
Members
448,969
Latest member
mirek8991

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top