I have created an add-in file and placed it in the Microsoft add-in folder. Inside 'ThisWorkbook' of the add-in, I have it installing a menu command button or uninstalling the button (Depending on if you are installing or uninstalling the add-in)
My Goal:
I want another macro to run when I select the command bar button.
I'm using .OnAction = "Test_Macro"
I need the Test_Macro to be inside the add-in.
My Problem:
When I open up a random workbook, install the add-in, and press the button, I get an error saying "Cannot run the macro. The macro may not be available in this workbook".
But the macro is very clearly in this very same workbook. What is happening that I'm unaware of?
When you are in the VBA editor, right+click on the add-in in the left pane VBAProject('add-in') and highlight 'Insert' and select 'Module'
This is where you write the macro you want to use for .OnAction
Related
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?
I have an Add-In that I created to update other Add-Ins as I release new versions. The AddIn runs when it opens (when Excel starts), it searches for new versions of other installed AddIns, and then the AddIn closes. If I try to open it from the code editor it just repeats this process. Any ideas on how I can access it?
If you hold the Shift key while an Excel file is opening, it will prevent any Automatic macros (e.g. the Workbook_Open event) from running.
Alternatively: Before you open the file, go to the Immediate Window (Ctrl+G) in the VBA Editor (Alt+F11) and run the following code
Application.EnableEvents = False
Then, when you are finished, run this to reset everything:
Application.EnableEvents = True
You may want to look into binding GetKeyState, so that your Macro can check for the Shift key before it does anything and Stop if it is held down
I am learning EXCEL vba and was trying to create a macro that ran when EXCEL was opened. It was saved as "Personal Workbook" and now every EXCEL spreadsheet I open has this macro. Should have selected as "This Workbook". How do I get rid of that macro so that Workbooks open without it.
Thanks
The personal workbook will be in Appdata/Microsoft/Excel/XLSTART. Just remove it from there. To get to your app data folder press windows+r and type %appdata%
If you just want to remove the module in Personal workbook that was created, rather than the whole file:
In the Visual Basic Editor (Alt + F11 to open)
Find the PERSONAL.XLSB VBA Project in the Project Explorer (Ctrl + R to open in the VBE)
Press the little + sign next to VBAProject.
Press the little + sign next to the Modules folder in the project.
Find the module containing the code, right-click the module and select Remove ModuleName
Using the gui to get to the file.
In Excel
File -> Options
Click on "Customize Ribbon"
In the right hand pain there is a "Developer" checkbox that is unchecked by default, check it.
Now go to the "Developer" ribbon and click "Macros"
Click the macro you do not want an click "Delete".
So I've created a Macro in a PowerPoint Presentation and I would like to make this Macro readily available to someone else. From what I have gathered, the best way to do this is to create an Add-in.
I have come across several articles stating to do the following, but I am still running into problems:
Open a new PowerPoint Presentation
Create a macro using VBA
Exit VBA, and save the Presentation as a .ppam
Under the Developer Tab, click on the "PowerPoint Add-ins" button
Click the "Add New..." option, and browse for your recently created
.ppam file
Click Load
Click Close
Click Add-ins
You should now see your new Add-in
I have done everything mentioned above and can even see the new Add-in when I select PowerPoint Add-Ins. I'm here because I can't find a way to run the new Add-in, and I don't want it to automatically load on startup or to interfere with the presentation by creating a button on the slides. As instead, I would like to allow the user to run this Add-in from the Ribbon.
Thoughts?
First, save as PPTM. THEN save as PPAM. If you only save as PPAM, you won't be able to go back and edit your code later to correct problems.
To launch your add-in from the ribbon, you must include RibbonX code (a type of XML) to your PPAM or PPTM (best to add it to the PPTM ... it'll become part of the PPAM automatically then).
There's an excellent book on RibbonX that'll save you hours of time:
http://www.amazon.com/RibbonX-Customizing-Office-2007-Ribbon/dp/0470191112
This is a good starting point if you don't want to buy the book:
https://blogs.msdn.microsoft.com/jensenh/tag/all-office-2007-ui-posts/
While you can manually unzip PPTM/PPTX/PPAM files and add the RibbonX code using any text editor, it's silly to do so. Instead use this free tool:
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/08/07/7293.aspx
I have added a toolbar menu for my macro, so I can just press the button and it runs my macro from any excel document. Every time I run the macro though, it opens the source file containing the macro. Is there a way that it won't open the source file and just run the macro? (even opening and closing wouldn't too much of an issue, but I'd prefer not opening it at all)
I haven't been able to find any information about this, so all help to get me started is appreciated.
You can't pull code out of the air to run it; Excel's going to have to open the file the code's stored in to run the code.
If I understand it correctly, you can create an Excel add-in from your code and have the add-in load automatically when Excel starts. Your code will always be available in that case.
This seems like a good place to start:
http://msdn.microsoft.com/en-us/library/aa140990(v=office.10).aspx
USE YOUR PERSONAL MACRO WORKBOOK
Open the VBEditor and find the module containing your macro.
Copy that code.
Now in the VBProject Panel on the left, locate your PERSONAL.XLS or PERSONAL.XLSB project. This is the project where you store macros you want available at all times. Add a module to that project and put your code into it.
Now update your "button" so that it points to the macro in that workbook and you're good to go.
On the off chance your PERSONAL.XLS project does not exist, use the macro recorder to record a "junk" macro and be sure to set it to "Store Macro In: Personal Macro Workbook"... that will create it for you the first time.