Make a VSTO Excel 2016 Workbook Application portable/without setup? - excel

I have the following situation:
I developed a VSTO Excel 2016 Workbook, which triggers some code when you copy/paste an Excel Worksheet in the above mentioned Workbook. When i publish the project (Project Properties > Publish > Publish Now), Visual Studio creates the following in Folder:
Excel Workbook(.xlsx)
VSTO file(.vsto)
setup.exe file
The Workbook only opens without error when i first run the Setup, wich obviously installs the .vsto file.
My Question:
Can you generate/publish a .xlsx Workbook which is portable, i.e. you dont have to install anything since the Code is already in the .xlsx file? Because I dont want to run the setup.exe everytime when i switched to another PC.
Or is there even an alternative solution to VSTO/my problem?

The only way to embed and distribute code with a workbook is to use VBA.
There is no way to embed a VSTO solution in a workbook - VSTO was explicitly designed to not allow that for reasons of code maintenance and security.

Related

VBA - How run a Macro from another workbook without opening it?

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.

Excel 2013 - "At startup, open all files in": only works first time

Afternoon all,
I've just upgraded to Office 2013 and I'm trying to get to grips with it.
Since Excel 2003, through 2007 and 2010 I have created and used standard templates for new workbooks and sheets which I store in a specific location. I use the "At startup, open all files in" option in the Advanced Excel options to reference this location so each time a new workbook or sheet is opened, it uses my templates.
In Excel 2013 it works in the first workbook but any workbook after that I open just opens as standard. If I create a new instance of Excel by holding down Alt when I click on it, it also works correctly. It seems as if the change in Excel 2013 to open up workbooks in the same instance which behave as separate instances has the downside of the startup files not being accessed.
Does anyone know how to correct or get around this?
Edit: Same problem if I use the default XLStartup folder
SliderSteve

Saving VBA code as a separate file in Excel

I have a very complex Excel workbook, with an awful lot of VBA code and macros in it. For version control purposes, I'd really like to be able to save the code as separate files to the workbook proper - to split it off into modules. Is this a thing that's remotely possible?
You should also look into Add-ins (.xlam). These allow your modules/class modules to be referenced in other workbooks. If you deploy a tool to a workgroup then realize that you need to change a macro you can update the .xlam and it gets pushed to all workbooks that reference it.

How to copy a VSTO Document level worksheet without registery installation?

My understanding is that when I create a workbook VSTO solution, I need to register (implicitly or explicitly) the solution in the registry. When developing the VS takes care of this.
If I wanted to have more than physical xlsx files with different names and reuse the VSTO code what to do?
A simple copy/paste of the workbook file won't work of course. I don't want to register each new workbook in windows registry since this could be a serious hassle.
Typical case would be: Say a user collects monthly data in workbook xlsx file. You need to run the VSTO code in each workbook xlsx file separately. As a result you end up having 12 sheets per year. Using VBA, you could easily copy the files and change the names - How to do the same when VSTO is used?
I thought of using a template but I wanted to ask before I waste time on it.
I am using VS2010, C#, Excel 2007.

Recovering datas from an Excel/ActiveX spreadsheet

I'm having the following issue: I've an Excel spreadsheet with a lot of VBA codes and ActiveX controls, including RExcel formulas.
The Excel version is 2007.
When I try to open this file, Task Manager says Excel isn't answering and something starts like if Excel started running endless codes; I deactivated each control and it still seems broken.
I would like to recover at least some formulas I've written in that spreadsheet, but this is actually impossible by opening the spreadsheet in conventional way.
Could you tell me how I can "read" formulas and text in that spreadsheet without opening it by Excel?
Thanks,
Indeed have calculation set to manual for a start.
Now set your security settings such that macros and activeX are disabled:
Excel Options > Trust Center > Trust Center Settings... > Macro Settings > Disable all macros with notification
For ActiveX I am not sure if there is a menu in excel-2007 like for macros, but if there is make sure it is set to not run as well.
Now you can open your excel workbook and it will not run your macro's and shouldn't auto calculate or update!
ADDED: I have had something like this in the past and this is what worked in 1 occasion: install an other office excel application, like open office (the calc application has the excel functionality) and see if it opens in that application. Then if it does, save the file (under another file name) and close it. Open the new file under MS Office Excel, and see what is still recoverable.
Good luck!
use a tool like 7zip to extract the files. the sheets/formulas are in the .xml
the code in a macro enabled spreadsheet is in a .bin file
this can be read with MalOfficeScanner

Resources