I created an XLAM file which displays a customized ribbon tab, the buttons of which call various macros.
How do I get this add-in file to load automatically when opening another xlsm file?
Currently, the only way to display the add-in ribbon is to open the XLAM file first, then open the other XLSM file. Only then will the custom tab appear.
I appreciate your help.
Many thanks,
KS
In the ThisWorkbook module of the workbook (not the addin) enter something like this:
Private Sub Workbook_Activate()
Application.AddIns("MyAddin").Installed = True
End Sub
Private Sub Workbook_Deactivate()
Application.AddIns("MyAddin").Installed = False
End Sub
The word "Installed" is a bit misleading, as it only indicates whether the addin is checked or unchecked in the Addins Menu.
If by chance the ribbon is only for one workbook you should just attach the ribbon to that workbook.
If the ribbon is for multiple workbooks, people generally take the opposite approach to what you are doing, i.e., create an addin that uses application-level events to turn menus on or off when specific workbooks (or workbooks with a specific characteristics) are activated or deactivated.
If you add the file to C:\Users[user]\AppData\Roaming\Microsoft\Excel\XLSTART it will add the ribbon every time you open Excel.
Related
I want to open only the userform when I open the excel sheet. I used the below code but other excel also become invisible. I want to display other open excel file and only macro contained file should be disable.
Application.Visible = False
UserForm4.Show
If I see well what you mean, I think the best thing to do is to make your xlsm file an add-in. In order to do this:
1) Call the UserForm4.Show into the Workbook_Open event of your .xlsm;
2) Save your workbook as Excel Add-In (extensions: .xla or the newer .xlam);
3) Enable the add-in on Excel, so every time that a workbook is opened you can show the form and not the entire workbook, so avoiding also to let the EXCEL.EXE instance open (that will remain so if the Application is Visible=False, because no user would see it after closing the workbook they're working with).
Add-ins have a great power in terms of use and distribution, I suggest you to get started from here and go deeper into this very nice tool.
Add the following code to the user form...
Private Sub UserForm_Initialize()
ThisWorkbook.Windows(1).Visible = False
End Sub
Private Sub UserForm_Terminate()
ThisWorkbook.Windows(1).Visible = True
End Sub
I am new to VBA/Excel programming, I am refreshing a pivot table using a macro. I have the following VBA code on one of my sheets.
Excel version : 2013 ( saving my file as macro enabled workbook)
Private Sub Worksheet_Activate()
RefreshPivotTables
End Sub
Private Sub Worksheet_Deactivate()
RefreshPivotTables
End Sub
The code works fine when I switch back and forth after enabling the macro, but when I open the Excel doc I get this "Enable macro ribbon" at the top which is preventing the macro from running. I need to switch to another tab and come back to my original sheet to activate the macro.
Is there a way to set "Enable Macro" for the workbook by default / some code that will do this on behalf of the running user? I cannot expect all my users to switch workbooks and come back to see the refresh happen.
Go into the options in Excel and then to the trust center settings. Put the location in as a trusted location.
Alternatively on my machine if I open a sheet, enable macros then close it again a few times Excel asks if I want to make this a trusted document.
I have faced one problem in Excel 2013. In my project, I have a userform that contains a listbox which lists names of all opened excel books.
When a user clicks on a particular name in the list, the appropriate book is activated. So the userform is always on top and while the user is clicking on the names in the list, he can see all opened workbooks getting activated one by one behind the active userform.
This is the way it used to work in Excel 2010.
Now, after upgrade from 2010 to 2013, if a user clicks on a name in the list, selected workbook gets activated but the userform disappears.
What exactly has been broken in Excel 2013 and what is the way to bypass this problem?
Yes, the default behavior has changed. In Pre Excel 2013, The different workbooks are shown within one main Excel window if opened in the same instance. But in Excel 2013, they are shown in their own window. And because of this a modeless userform will only be visible on top of the workbook that was active when the userform was loaded.
And I don't think this has a fix yet. It is by design and may not be fixed.
#Siddharth, based on what you said, I think I have a solution. When you open a form, it will only show up on top of the ActiveWorkbook. As long as all the code is in the same code thread (not sure if terminology is right) , you're stuck with the same workbook; But if you use the Application.Run or Application.Ontime commands it seems to start it's own code thread, which is independent enough to work. Just Activate the workbook/sheet first, and then Unload the form and remote call the macro that showed the form in the first place.
Unfortunately, you need to use Unload instead of Hide, because of the aforementioned issue; which means you need to save any/all options selected.
Private Sub lstFiles_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ThisWorkbook.Application.Workbooks(lstFiles.Text).Activate
Unload Me
Application.Run "USER_Macro1"
'Application.OnTime Now(), "USER_Macro1"
End Sub
Private Sub USER_Macro1(Optional Control) ' As IRibbonControl)
ModelessForm.Show vbModeless
End Sub
I tested it in Excel 2013 and so far it even seems to work regardless of the Screenupdating = false issue seen elsewhere.
I have the following peace of code to exec a xlam file when I open the excel file:
Sub Auto_Open()
Application.OnTime Now + TimeValue("00:00:05"), "readCsv"
End Sub
Sub readCsv()
....
End Sub
I add it as Add-ins so every file I open has the xlam file on it. If there is no other excel file opened, it works perfectly but after that without closing the excel file I open a second one it does nothing. I need to exec the code even if there is another excel file opened. Is that possible?
I also try to do it writing the code in ThisWorkbook but the result is the same, If there is another excel file opened it does nothing.
To use your macro in any of the worksheet opened (irrespective of name) you can only possible do it by using a personal workbook Here is the Link
If the above doesnt suits you can prepare Add-ins and install it for users (Google for it if this is the case)
EDIT:
How to get add in in all opened files....
Goto File - Option - Quick Access Toolboar - From the dropdown "Choose Command from" - select Macros then select add-in macro - Add it, Below there would be a modify button Select the icon you like from it - OK
Now you will be able to see the icon with the addin function linked on top of the excel - click it for functioning, it will remain there forever ( if missed you can reapply the settings)....
The procedure are for 2010, for 2007 it should be similar....for 2003 there is a different way to achieve it...
Copy the .xlam to C:\Users[user]\AppData\Roaming\Microsoft\Excel\XLSTART. It will load every time you open Excel.
I've got a VBA macro in an Excel 2003 spreadsheet and I'd like to 'install' it on a machine running Excel.
I created a 'Trusted Location' on the local machine, and I know how to copy the module to the existing workbook and assign a key combination to invoke it, but I don't know how to make the macro appear automatically when someone starts Excel. Help?
The simplest solution is ( both for xl2003 and xl2007 ) to copy your xls containing the macro to the path = Application.StartupPath from your client machine ( can build a simple vbscript installer which instantiates excel and retrieves this information ).
This way your macro will be available in any workbook opened since the xls files located in startuppath are loaded at excel startup.
I remember the old way was to save your macro in your Personal.xls
workbook - then it would be accessible
any time you opened Excel - has this changed for 2007?
That was a way. A better way was (and is) to create an Add-in, which you can then enable & disable via Tools->Add-ins. (An Add-in will remain enabled even if you close and re-start Excel). You can save any .XLS file as an Add-in (.XLA).
Within your Add-in you could just use an Auto_Open method:
Private Sub Auto_Open()
DoStuff
End Sub
...or, you could hook up the Workbook_Open event, as Ryan suggests.
Of course, since the user can disable the Add-in, you also want to do the reverse in Auto_Close (or in the Workbook_BeforeClose event).
Actually, if you use events it'd be better to use the Workbook_AddinInstall and Workbook_AddinUninstall events. Using those is slightly more "correct", and also has the benefit that the 'close' event doesn't fire if you close Excel and then hit Cancel when prompted to save.
I'm not sure what you mean by 'appear', but you can execute it automatically by calling it from
Private Sub Workbook_Open()
End Sub
in the ThisWorkbook object module. Is that what you're looking for?
I remember the old way was to save your macro in your Personal.xls workbook - then it would be accessible any time you opened Excel - has this changed for 2007?