Decide which ribbon tab to be selected - vb.net

The program, that I'm working on, has a separate (additional) Add-in tab in the Excel ribbon. And there are our custom controls, etc. Some of the controls open a new workbook (new Excel window).
In Excel 2010, when the new workbook is opened, our custom tab is selected by default. But in 2013, the first (Home) tab is selected.
In the project, there is no code that controls which tab to be selected by default in a newly open workbook. That is why I am wondering it works in 2010, but not in 2013?
I researched about that, but I could find mostly articles about "how to create new tab", etc.
Any ideas and suggestions are welcome.

This should be the fix you're looking for:
yourRibbonInstance.ActivateTab("tabID")
keep in mind that the id of the tab might not be the same as its displayed name.

Not sure if this might be overkill but you could use a macro that runs on the workbook open event to activate the sheet you want to see first..
Sub workbook_open()
Sheets("Sheet2").Activate
End Sub

Related

Under Excel O365, the custom ribbon tab does not always populate

Using an .xlam project with a fully working custom ribbon, I have found that the new tab will sometimes show nothing when clicked on. It is intermittent. The global RibbonUI object is available and running an .invalidate will then show the ribbon. However, the .invlalidate attempts prior to the tab being viewed do not seem to change this behavior. I have to view the tab and then run the .invalidate manually (with a macro button) to see the ribbon appear.
I am scratching my head trying to find a slick way of making this new custom tab populate 100% of the time.
For the benefit of those that come across this issue, I have found the root cause and a solution. This is Excel O365 specific.
If you have a custom ribbon tab set up and working, try this. Open Excel, create a blank workbook, then double-click on a cell to put it in "edit mode". Click on your custom ribbon tab. Blank, right?
This "cell in edit mode" is what was causing Excel O365 to fail to show my custom ribbon. Excel O365 starts up on the "File" screen. Prior versions always opened to a blank sheet. If you click on "Blank workbook", the ribbon displays fine. If you DOUBLE-CLICK on "Blank workbook", the first click opens the workbook and the second click puts a cell into ""edit mode". In this state, clicking on your custom ribbon tab shows nothing.
The work-around
Private Sub WorkbookActivate(ByVal Wb As Workbook)
Application.SendKeys "{ESC}"
...
You may see a cell go into edit mode for one blink but it then exits edit mode. Click on your custom ribbon tab. It will now show the ribbon controls as designed.

open custom ribbon in other workbook VBA

I am writing some vba in excel to create another excel report.
This report needs to have adjusted the header /footer, which my company have through their own custom ribbon in Office.
If I am in my main workbook, I am able to activate the ribbon by following code:
Application.SendKeys ("%HY2%")
But after I created my excel report it seems like the custom ribbon is not given time to activate or something.
I then call the report like this
code:
Workbooks.Open Filename:="C:\Users\ccc\sss.xlsx"
and then try
code:
Application.SendKeys ("%HY2%")
Then it is possible to call the Home tab, but not the custom one.
I have tried to delay the code using wait function, sleep function and Do While (check if ready)
But during all these, it seems like excel tabs is on "hold", it is not activating the custom ribbon. Therefore my code opens the Hometab, but it cannot find "Y2" Ribbon.
I have tried activating the main workbook to do some random code, then going back again and activating the report again, but no...
Can anybody help please?

Excel VBA add right-click button to addin

I am trying to make an Addin with Pivot right-click button.
All the macros are working in the addin perfectly on every workbook that I open.
The problem is that the right-click buttons don't appear in other workbooks - only in the one with the addin.
Screenshot
As you can see I have written the code in ThisWorkbook module, and the Subs are Private. - I guess that somewhere here is the problem.
Would be very grateful if somebody can help.
Ah, I found the problem.
Obviously, the first part of the code was preventing the buttons to appear in other workbooks.
Other than that, Temporary:=True. it should be False.

How to open add-in automatically on opening excel workbook

I want to know how I can have a workbook automatically open an add-in? The problem is after I create the workbook in code -- call it "A.xlsx" -- I want to add code to it (on creation) that will open the Excel add-in "B.xlam". How do I do this? Creating the workbook is no problem; that part is sorted, and I just want to add the code to that workbook, so that every time it opens it must open the add-in "B.xlam" with it.
From the Developer Ribbon, click Add-Ins,
then click Browse, then navigate to the location of the desired add-in file, then select it, and make sure the checkbox is selected for it.
Alternatively, store the code in PERSONAL.XLS/PERSONAL.XLSB, and these macros/functions will be available to all open workbooks.
If you're somehow asking how to programmatically insert code in to new workbook files, I'm afraid you're out of your element. If you don't know about the Workbook_Open event, nor how to manage your Add-Ins, etc., manipulating the VBE is a pretty high-level operation, and I would not be able to help you with that.
Update from comments
Here is one method that will export VB Components to a specific path, example also includes code to import modules from path to a workbook. You should be able to adapt this to your purposes.
http://www.rondebruin.nl/win/s9/win002.htm
If you have specific problems implementing this solution, please post as a new question.

Excel won't show the workbooks worksheets

I have an Excel Workbook containing three worksheets. However all sheets seem to be hidden dispite that their visibility is set to xlSheetVisible (Found by looking at the worksheet properties in the VBA editor).
This is what I have tried so far to solve the problem.
Searched Google for help, but all similar problems have been solved by changing the Visibility from xlSheetHidden to xlSheetVisible. But in my case that setting is already set to xlVisible.
By using VBA I have tried to activate a sheet without any result.
By reading this you might have guessed that I am able to see and access the worksheets from the VBA editor.
Despite that looking at the normal Excel userinterface, all buttons are disabled and clicking at the office/file button in the topleft corner doesn't allow me to save the workbook. However if I make any changes to the VBA itself and tries to close the workbook then Excel asks whether or not I would like to save the workbook.
Everything you describe leads me to believe you're hiding the workbook window, not the worksheets. When a workbook window is hidden, all the sheets become hidden and much of the functionality from the toolbar greys out.
In the Visual Basic Editor, you'd also be able to see all of the worksheets and their visibility would be xlVisible, yet they cannot be seen on the screen. This is because they ARE visible, but the window which displays them is not.
Please try clicking the View tab in the toolbar, and then under the Window pane, click Unhide.
If this doesn't work, then try toggling visibility of the workbook.
It sounds like this may really be your problem...
http://vbadud.blogspot.co.uk/2010/08/hide-sheet-tabs-using-vba-hide-excel.html