Invoking the Activate dialog for sheets - vba

I want to invoke the Activate dialog for sheets in a workbook such as below. This dialog can be called manually by right clicking on the arrow button at the bottom left of Excel (2013).
I tried this:
Application.Dialogs(xlDialogActivate).Show
But instead of showing the list of sheets, it shows the list of open workbooks:
How do I call the Activate dialog for sheets?

You could create your own dialog box if you want. Create a userForm and populate it with the names of the Worksheets upon activation. You can see what the user selected through the selected function, e.g.
ListBox1.Selected(i)
You can then call a sub with the name of the Sheet and activate it, e.g.
Sub ChangeSheet(SheetName)
Worksheets(SheetName).Activate
End Sub

An alternative is to show the Sheet Command bar:
Sub ShowSheets()
Application.CommandBars("Workbook tabs").ShowPopup
End Sub
Content salvaged from comments by Scott Holtzman and Davesexcel.

Related

Excel Form pops automatically when sheet opens

I have a specific worksheet with 2 sheets(Sheet1 & Sheet2). For Sheet2 I have implemented a form for the table (Using the basic Excel Form from the top bar).
My problem is that I have to make the form appear automatically every time I open Sheet1 (even if the data from the form will be completed in Sheet2).
Is this possible? Or how can I do it? (I can also use VBA)
To show the DataForm associated with a Worksheet, you use the command Worksheet.ShowDataForm (MSDN Article)
To show the DataForm for Sheet1 whenever you go to Sheet2, you can use the Worksheet_Activate event in Sheet2, like so:
Option Explicit
Private Sub Worksheet_Activate()
Sheet1.ShowDataForm
End Sub
A quick way to figure things like this out is use the "Record Macro" button, carry out the action you want, and then hit "Stop Recording" and look at the macro

vba macro list box not letting editing some macros

I have an Excel project with a lot of macros.
What I want is assign macros to buttons in the ribbons.
For that I created macros like:
Sub R10_parallel_device()
help.helpON ("parallel_device ")
Call sub_novelty_claims("parallel_device")
End Sub
So the three conditions are met:
a) the macro SUB R10_parallel_device() do not accept parameters
b) it is not private
c) It is not hide
when I go to the list of macros I see all the list of macros named Rnn but all THE BUTTONS ARE GREY OUT EXCEPTFOR CREATE.
Now if I click in that sub for instance SUB R10_parallel_device() I can not edit it and if I click "create" excel sends me to a new created module where
Sub R10_parallel_device()
End Sub
appears.
&
When I go to file/options/ribbon if I want to add that macro to a button it is listed and it is possible to assigne the macro to a button but it would not run, giving the error that such a macro is not found.
NOTE: I checked which macro are listed thisworkbook/all/ etc.
note2: this did not help me. this neither
thx
Confirmed it's the macro names - go to Developer -> View Code (or type Alt + f11), then select the module with your code in it and rename them. For whatever reason it's that R# syntax:

How to select an ActiveX Option/Radio Buttons in Form Controls

I have a Form Control with ActiveX Radio/Option Buttons in it.
The Form Control name is Side and contains Option/Radio Buttons with names xOption, oOption, and randomSide.
How would I be able to create a Macro that would allow me to set the radio buttons to a certain value upon opening the workBook. Recording a Macro of me clicking options results in a blank Macro. I've Already tried:
ActiveSheet.Shapes.Range(Array("Side")).Select
ActiveSheet.Shapes.Range("xOption").OLEFormat.Object.Value = 1
But this gives me error 1004 and other codes give me error 91. I'm really new to VBA so if I look stupid you know why.
Try something like this, using Worksheets instead of ActiveSheet:
Private Sub Workbook_Open()
Worksheets("your sheet name here").OLEObjects("xOption").Object.Value = 1
End Sub
As you want it to be selected after opening the sheet. Place this on ThisWorkbook.
You may try something like this...
ActiveSheet.OLEObjects("xOption").Object.Value = 1

VBA auto hide ribbon in Excel 2013

How to Auto-hide Ribbon in Excel 2013 in VBA? I would like to achieve exactly what I get by clicking on the upper arrow icon at the right top of Excel menu marked with blue in the picture below and then clicking on the first option marked with orange:
I would be also interested in VBA switching back to the third option Show Tabs and Commands. Important thing for me is to keep in the Excel menu the upper arrow icon (marked with blue).
I have tried hints shown in this thread: VBA minimize ribbon in Excel
but I am not satisfied with results.
Attempt 1
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)
This is good but hides the blue icon.
Attempt 2
CommandBars.ExecuteMso "MinimizeRibbon"
This is close to what I want. This keeps the blue icon but does not hide the entire menu. It switches to the second option displayed in the picture Show Tabs.
Attempt 3
SendKeys "^{F1}"
The attampt does not work at all. Moreover, it is supposed to imitate the attempt 2. So even that would not satisfy me.
I can't see that anyone else has brought this up... This isn't a workaround, this is the actual idMSO for what I think you're looking for. This code makes my excel window look like everything is gone the same way the first option does for Auto-Hide Ribbon.
Before the code runs, my window looks like this, in the 'Restore' size:
Running the following code:
Sub HideTheRibbon()
CommandBars.ExecuteMso "HideRibbon"
End Sub
Will make your window look like this, in the maxamized window size (just like what would happen if you were to press the Auto-Hide Ribbon button manually):
If you want the ribbon automatically hidden when the workbook opens, put this in the workbook code:
Sub Workbook_Open()
CommandBars.ExecuteMso "HideRibbon"
End Sub
Alternatively, to achieve the same thing, you could put this code in a module:
Sub Auto_Open()
CommandBars.ExecuteMso "HideRibbon"
End Sub
If you want the window to revert back to normal, you run the exact same code again. In other words, the following code would make no visual change at all when ran because the idMSO "HideRibbon" is a toggleButton:
Sub HideTheRibbon()
CommandBars.ExecuteMso "HideRibbon"
CommandBars.ExecuteMso "HideRibbon"
End Sub
If you want a full list of all the idMSO in excel, click the following that apply to you: Excel 2013+, Excel 2010, Excel 2007
I use this for presentation purposes
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayHeadings = False
Application.DisplayFormulaBar = False
Application.DisplayFullScreen = True This is what i used to hide the ribbon
Probably you should do something a little more complicated:
Use CommandBars.ExecuteMso "MinimizeRibbon" to show/hide the ribbon.
Depending on what you want, you may show/hide all other tabs in the ribbon. E.g. use something of the code here -> Excel Hide/Show all tabs on Ribbon except custom tab
Thus 2 steps:
Step 1 - show or hide with the CommandBars.ExecuteMso
Step 2 - show or hide the rest of the tabs with some macros from the link.
A little big workaround, but you will get what you want.
I call this macro on Workbook_Open to check for the ribbon and if not hidden, it will hide the ribbon (I actually have it located in another Sub that also removes the formula bar, status bar, headings, and gridlines at Workbook_Open)...
Sub HideRibbon()
If CommandBars("Ribbon").Controls(1).Height < 100 Then
Exit Sub
Else
CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub
Then I call this macro on Workbook_BeforeClose to check for the ribbon and if it is not shown, it will show the ribbon for the next excel spreadsheet that is opened.
Sub ShowRibbon()
If CommandBars("Ribbon").Controls(1).Height > 100 Then
Exit Sub
Else
CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub
This eliminates the chance of hiding the ribbon when the workbook is opened and a user then manually showing the ribbon which in turn would reverse the show on close and actually hide the ribbon. On open, the ribbon would then be shown again. This will keep it the same every time on open and close of the workbook.
Give this a try:
Sub ShowHideRibbon()
If CommandBars("Ribbon").Controls(1).Height < 100 Then
CommandBars.ExecuteMso ("MinimizeRibbon")
Else
CommandBars.ExecuteMso ("MinimizeRibbon")
End If
End Sub
Or this:
Sub ShowHideRibbon1()
If Application.ExecuteExcel4Macro("Get.ToolBar(7,""Ribbon"")") Then
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)"
Else
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", True)"
End If
End Sub
First, go to the Excel Options, and go to "Quick Action Toolbar".
From there, search for "Hide Ribbon" and add to the toolbar. After it's on the QAT, you can call it quickly with ALT+# (on my computer it's the 8th thing, so ALT+8 will auto-hide).
Then just add a sub that does SendKeys ALT then 8:
Sub Macro1()
ActiveSheet.Activate
'Cells(1, 1).Select
SendKeys "%0", True
SendKeys "8", True
End Sub
Note: I know it's silly to have ActiveSheet.Activate, I just added that to test the macro. Depending on how it's being called, you can remove/comment out that line. The % is equivalent to ALT, and technically, I have to press 0 then 8, hence the two lines.
To get this code to work in excel 2016 you will need the following code in the "ThisWorkbook" mode.
Credit goes to BigBen - not me
Private Sub Workbook_Open()
application.CommandBars.ExecuteMso "HideRibbon"
End Sub

Macro enabled button VBA

I'm working with VBA macros and I have a macro enabled button of which I want to disable from being clicked when the workbook is first opened. Is there anyway to do this. The macro behind it just leads to another worksheet. ![enter image description here][1]
Any help would be great
Thanks
If your button is an ActiveX Command Button, put the following code in ThisWorkbook:
Private Sub Workbook_Open()
Worksheets("Sheet1").OLEObjects("CommandButton1").Enabled = False
End Sub
Change "Sheet1" to reference the sheet that contains the button and change "CommandButton1" to reference the name of the button.