I make a lot of workbooks where there is no data in the workbooks themselves, but there are macros and forms attached. I generally format these in .xlsb or occasionally .xlsm file format, but I'm wondering if there is a format where there is no actual workbook attached. Just like a file you can open in Excel that will launch the macro?
It just seems pretty inefficient to include a blank workbook that I just autohide on load.
Depending on the version of Excel, when you load up Excel it automatically opens a Personal workbook which isn't visible.
Normally this is created when you record a macro and close all windows. It will then ask you to save it to the file. I would then set up shortcuts for the Macros.
Related
I wanted to save all my VBA Project in a Excel workbook (or other type of file if possible) and then embbed it to run in another workbook. I've seen topics about it but only found ways to run the macros opening the first sheet.
I want to run a macro from a first workbook in a second one without opening the first workbook to do it. How can I do that?
Save the file with the macros as a xlam file and Excel can load them each time Excel opens.
You need to open File -> options -> add-ins.
At the bottom there is a button Go to (or something, I don't have English Excel on the current computer.)
Then add the file to the list by clicking Browse and finding the file you just saved as xlam file.
Two scenarios comes to mind:
1) You have a second macro for personal use and can save it locally (save in: %USERPROFILE%\AppData\Roaming\Microsoft\Excel\XLSTART). This will allow you to create quick-buttons for your macros, etc. These types of macros open with Excel and will be separate VBA Projects inside of the default VBA editor.
2) You have a network or drive that multiple users need to access, so each user has a macro in their file (.xlsm or .xlsb), where that internal macro reads Application.Run "filepath\workbookname.xlsb!macro", which also allows you to call a private subroutine (note that you could use Call, but Application.Run will ensure that even Private macros are able to be accessed). This shouldn't require the other workbook be open, though I have personally had one user whose computer always opens the other file, regardless.
Edit:
Third scenario (really 2b):
3) You have files where you want to regularly access another file... you will follow a similar approach to point 2 where you make a macro to Application.Run, though you can save that macro in your XLSTART folder... this will allow you to have a source macro location where others may also want to access and utilize. The source document would allow you to maintain 1 file for many users.
Your answers were great! Great to know about XLSTART folder from #Cyril, but based on #Andreas answer I found my path.
The "problems" with adding an Add-In as #Andreas said, are cause my VBA Project would be avaliable on the VB Editor to every workbook on that computer, and to run my macros I'd have to use Application.Run("workbook.xlam!Macro").
Then I found References, which I have the same features, including I can delete my .xlam file to remove my code, and don't have the problems I mentioned above.
Adding my VBA .xlam file as an reference, it'll be avaliable only to that specific workbook and I can run my macro just like it was on the same workbook.
For general knowledge:
ADDING A REFERENCE:
1- Save your project as an Excel Add-In (.xlam file)
2- Open your target workbook, go to the Visual Basic Editor
3- Go to Tools > References > Browse... find your .xlam file and make sure it's checked.
4- Done! Now you'll see the project on the editor and can run your macros just like it was on the same workbook.
I've been using ADO to process many Excel .xls and .xlsx workbooks without any problems. Recently I tried to process a .xlsm workbook to load to an Access database. The workbook contains several macros that are run every time a user opens a desktop version of Excel. The macros update "yesterdays" data with "todays" data. Unfortunately when I read the workbook programmatically ADO is returning "yesterdays" data. This means to me that the macros are not running when I open the workbook with ADO. Any suggestions. Hope I don't need to rewrite the code to open an instance of Excel to handle the workbook.
ADO accesses only the data saved in the workbook. Nothing vba (or any other) code does dynamically when the workbook is opened in Excel is available. Excel macros can only run when the workbook is open in the application interface.
Either your process needs to duplicate what the macro(s) are doing in order to update the sheet data or, yes, indeed, you need to first open the workbook in the Excel environment and execute the macros, then SAVE the changes to the workbook.
Im working with MS Excel files and need to copy/transfer pars from one excel file to an other. (I know it is possible to copy sheets... but there has to be a better solution)
I'm working with multiple monitors/screens to display MS Excel file. (but all on juist one Computer. But somehow i cant display two files at the same time.
Is there a way to solve this?
What is the reason this isn't possible? (is it because, in Excel VBA macro's there can only be one open workbook. to prevent you ending up accedently editting multiple excel files at the same time?)
I don't think so, because the shoeld both be able to be vieuwed at the same time... but i only need one to be selected to edit.
Specs:
- Dell Workbook
- Window 7 Professional
- MS Excel (Office 2010)
Thanks in advance,
best regards, Cornelis
In excel 2010, each time the excel application is opened it can have many workbooks open. See the max/min/restore buttons in the top right corner of the excel window. There is one set for excel and another set for the active workbook. Restore the workbook window and you will be able to arrange it and any other workbook that are open.
Note that you can copy sheets between any workbook open in the same iinstance of excel.
you can open excel more than once (ie opening many instances) and the workbooks open in each instance are treated differently than when they are all opened in one instance.
I have a workbook with multiple sheets. I press a (ribbon) button and a subroutine saves multiple sheets as .csv, shells out to some java code, then comes back. The problem is: once it comes back, the workbook has been converted to a .csv file (the last one saved) and no further .xlsm operations are possible.
How do I fix this?
Amendment:
Has nothing to do with Java or shell. WHENEVER I do this:
Sheets("someSheet").SaveAs Filename:=someName, FileFormat:=xlCSV
this changes the ENTIRE workbook to someSheet.csv. Then, the behavior of the workbook gets weird. I haven't been able to save as .csv without changing EVERYthing.
Use SaveCopyAs.
It leaves your original workbook as is and saves a copy. Requires 2007 or newer but since you mention a ribbon button that should be fine. From the link:
ActiveWorkbook.SaveCopyAs "C:\TEMP\XXXX.XLS"
http://msdn.microsoft.com/en-us/library/office/bb178003(v=office.12).aspx
In Excel, the Save As operation, creates a new copy of the workbook with the new name and format/style, then closes the old one.
A .csv file doesn't support macros, so your workbook is behaving as designed.
In order to get back to your original workbook after doing the Save As, you will need to re-open the original workbook and then close the new .csv workbook.
Otherwise, you could come up with a custom Export method to just export the data on each sheet to a .csv file, but that seems needlessly complex.
I have a reasonably complex macro that I need to run on multiple different excel sheets, this macro is updated periodically and whenever a change is made its necessary to change it in each individual excel sheet. is there a way to get each excel document to refer to the one macro?
for example if i had a hierarchy like this:
DOCUMENTS:
-xlsheet1.xls
-xlsheet3.xls
-xlsheet2.xls
MACROS:
-macro1.bas
where there was a button in each sheet that ran macro1 when clicked.
I would recommend either moving that macro to your personal file or create an Add-In
Working with Personal File
Topic: Create and save all your macros in a single workbook
Link: https://support.microsoft.com/en-us/office/create-and-save-all-your-macros-in-a-single-workbook-66c97ab3-11c2-44db-b021-ae005a9bc790
Quote from the above link:
When you first create a macro in a workbook, it works only in that workbook. But what if you want to use the macro in other workbooks? To make your macros available every time you open Excel, you can create them in a workbook called Personal.xlsb. That’s a hidden workbook stored on your computer, which opens in the background every time you open Excel.
Creating an Add-In
Topic: Creating Excel Add-ins
Link: http://www.ozgrid.com/VBA/excel-add-in-create.htm
Quote from the above link:
I am often asked by users 'what is the best way to distribute their macros?' My answer, is without doubt via an Excel Add-in. After all, this is what Add-ins are for. For those that are not sure what an Excel add-in is, it's is nothing more than an Excel Workbook that has been saved as an Add-in, File>Save as \ Microsoft Excel Add-in (*.xla). Once saved and re-opened the Workbook will be hidden and can only be seen in the "Project Explorer" via the Visual Basic Editor. It is NOT hidden in the same way as the Personal.xls as this can be seen (and made visible) via Windows>Unhide.
The Personal file is good for having a macro across any number of workbooks on a single computer. In a networked environment with multiple users, you could simulate the Personal file by having a single workbook with your macros in it and coding all other workbooks to open and hide this workbook when they start up.