Macro User Input Directs to Tab

Jer-XL-emy

Board Regular
Joined
Aug 27, 2007
Messages
60
Hello, It been awhile since I have ask for help and come to the place where the macro genuises reside.

My question, (I thought would be an easy one to search for but I guess my key words do not work)

I want a user input box to pop up when a workbook is open and depending on the user input direct to a certain tab (worksheet).

To be more specific I have one worksheet dedicated and formatted for on screen viewing and I have another formatted for print.

depending for what the user needs it for is the tab where they will get directed.

Any ideas.

Thanks in advance for your help : )
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Simplest way, with obvious modifications. Put this in the ThisWorkbook module.

Code:
Private Sub Workbook_Open()
  Dim answer As VBA.VbMsgBoxResult
 
  answer = VBA.MsgBox("Click Yes for printing." & vbCrLf & _
              "Click No for viewing." & vbCrLf & _
              "Click Cancel to exit.", vbYesNoCancel)
 
  If answer = vbCancel Then
    ThisWorkbook.Close False
  ElseIf answer = vbYes Then
    ThisWorkbook.Worksheets("Printing").Activate
  Else
    ThisWorkbook.Worksheets("Viewing").Activate
  End If
 
End Sub
 
Upvote 0
Thank you very much iliace - it works great manually - although how do I get it to do it automatically when the workbook opens? - what step am I missing?
 
Upvote 0
There are two types of code modules available in Excel VBA: Standard Module and Class Module. There are three special instances of class modules as well: Form Module, Sheet Module, and Workbook Module. Any event that pertains to a class (user-defined classes, form classes, sheet classes, and workbook classes) must go in that object's code module.

Workbook_Open is a workbook event, therefore it must be placed in the workbook module. By default, the module is called ThisWorkbook. The code will not auto-run when placed in a standard module, or any of the other special class modules.
 
Upvote 0
It Works like a charm - Thank you very much iliace - sorry I forgot how the VBA editor interface works as it been a while since I need a macro - thanks the script and showing my monkey brain how to use it - have a great day
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,308
Members
448,886
Latest member
GBCTeacher

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