Vba project cant open if excel is already running - vba

I want to open my vba project from my USB stick, but if excel is already running with some other sheets (with new data) it won't open my vba project.
It only opens when my other excel sheets are closed or saved.
What can I do?
Is it possible to make a msgbox for telling the user that he must first save other excel projects (when I want to open the project while other excel sheets are not saved) ?

Note that Excel allows a filename only once to be opened, independent of where the files are placed. So C:\Documents\mysheets.xls and F:\memstick\mysheets.xls have the same name and only one can be open at the same time.

Have you tried to open a second Excel instance?
1. Open Excel with start/programs/microsoft excel or wherever
2. Open your macro in that second instance or just pull it into that new excel form.
should work i think...

Related

How do I save an Excel Add-In with VBA

I have an Excel Add-In which uses a worksheet in its workbook to save some preferences data (eg the last used value of a refEdit control on a userform).
I then save the add-in workbook using vba thisworkbook.save when preferences are changed in the userform.
I have found that this sometimes creates an xlsm file in myDocuments rather than saving the add-in in place (see also a copy of excel add-in is created in my documents after saving).
How can I save the add-in in place (in the add-ins folder) without creating a copy? Note activeworkbook.save wouldn't work as it saves the open workbook not the add-in.
I could alternatively create a temp file for the preferences but using the sheets in the add-in workbook seems a good place to store data.
As far as I know you can't have a file saved as an add-in and use the sheet on the file.
An add-in file is a VBA only file.
You say you want to save settings on the sheet. What about using the registry?
Saving data to the registry is very easy (actually easier than cells in my opinion).
To save a setting:
SaveSetting "MyAddIn", "Settings", "Username", "BOB"
The above line creates a value in the registry of windows with the value "BOB"
as "Username".
To get the setting from the registry you use:
Username = GetSetting("MyAddIn", "Settings", "Username")
You can read about the method here
The good thing about saving it on the registry opposed to a sheet is that you can't by accident delete or manipulate the data.
I found the answer: The user had two copies of Excel open (2016 and 2010). This resulted in the add-in file being locked by one of the two open copies of Excel meaning that the second copy opened the add-in as read-only and couldn't save the changes.
A rare bug and one I didn't foresee. I'm going to rewrite to save the preferences into an %appdata% file instead.
I'd advise people to avoid using thisworkbook.save with addins.
Thanks everyone for your help.

Creating a Macro That Can Run on Any Excel Sheet That I Open [duplicate]

How can I write macro in Excel that will work (to run with shortcut) on any excel document which I will open?
Is this possible?
You need to add your macros to Personal.xlsb in order to make them available to all the excel files. Choose Personal Macro Workbook in Record Macro dialog to do this quickly.
Source: http://office.microsoft.com/en-in/excel-help/copy-your-macros-to-a-personal-macro-workbook-HA102174076.aspx

Retreiving/reading excel macro without opening excel?

I wrote an excel macro that seems to have broken, unfortunately when I try to edit the macro in the VBA editor, excel itself crashes spectacularly. This seems to happen whether I open the VBA Editor before or after loading the problematic excel file.
Does anyone know of a way of viewing the VBA code that I've written without using excel to get there? Alternatively, can anyone get to the VBA code in (this excel file)(Link Removed) without it crashing their excel?
Unlike "Running Macros without opening excel" I don't need to be able to run the broken code without excel - just copy and paste it somewhere to fix it!
I created a fresh new excel file and open the VBA editor. Then I opened the one you provided, but I had put it in a non-secure folder. Excel prompted me the choice of opening it with macros disabled. I did, and I could see the code in the editor. :)

How do I correctly execute an Excel VBA macro?

My colleagues and I have created a userform with a suite of tools for doing tasks in Excel and Word
I'm quite familiar with spawning application objects from modules and closing them without effecting anything else - or other running copies of Excel.
However the user form must start some where - this leaves an Excel sheet open in the background.
I have tried Application.Visible = False but this hides all open workbooks - Kind of annoying if you have other worksheets open
I was thinking of a wrapper sheet which creates an Excel and runs the macro (spawning the macro in its own instance of Excel) - this works but then Im left with the wrapper sheet and potentially an orphan excel app if I close my parent.
Is there a better way than this to execute macros without affecting the rest of the user experience on MS office?
Yes, you can create an Excel add-in. Simply save the Workbook containing your code as an Excel add-in (select the appropriate file format in the "Save As" dialog) and configure Excel to load the add-in at startup in the "Options". You won't see anything of the add-in besides the functionality it provides.

Excel VBA - Call macro using add in

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.