Open Userform by a SpreadSheet by clicking on the Tab

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
I`ve created a Module Macro see below to open the user form.
Can`t work out how to activate the form.
Because I replace the worksheet with one of the same names I can`t put the code on to the worksheet itself.


VBA Code:
Private Sub Open_UserForm()

Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Job Card Master")


If ws.Activate Then

Body_And_Vehicle_Type_Form.Show False

End If


End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You need to use worksheet event to trigger macro. The macro is located in Worksheet class and you can select how to trigger it, not in standard module. Use

Private Sub Worksheet_Activate()

your code here

End Sub
 
Upvote 0
My issue is I can`t put this into a worksheet code. The tab gets replaced often with a tab of the same name.
I`ve put the Activate in the subline. Still no luck

VBA Code:
Private Sub Worksheet_Activate()

Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Job Card Master")


If ws.Activate Then

Body_And_Vehicle_Type_Form.Show False

End If


End Sub
 
Upvote 0
Let us know what is the process or what is your action?

What do you mean tab get replaced by same name? Why you want to replace if the name is the same? A bit confusing on what you were trying to achieve :)
 
Upvote 0
Can you try placing this in ThisWorkbook's code instead?

VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Sh.Name = "Job Card Master" Then Body_And_Vehicle_Type_Form.Show False
End Sub
 
  • Like
Reactions: Zot
Upvote 0
Solution
Let us know what is the process or what is your action?

What do you mean tab get replaced by same name? Why you want to replace if the name is the same? A bit confusing on what you were trying to achieve :)
It`s a template so uses the same name sheet but varying amounts of pages in the workbook.
The code brings in a workbook with sheets with different No.s of pages and deletes the old one.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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