How to know that a VSTO Word and Excel addin is being started by the Windows Explorer preview pane? - excel

I have noticed that when users have the Windows file explorer preview pane enabled and then view a Word or Excel file, that my VSTO addin is started. Further my addin starts again when the user double clicks on a excel or word file.
What properties in Word and Excel do I need to check at startup to know that it is the preview pane?
For people's reference I did find a discussion on this for Powerpoint in this SO question.

When Word and excel are started by the file explorer as a preview then what I have found is that you can check for a commandlinearg of -Embedding
Environment.GetCommandLineArgs().Contains("-Embedding"))
Detecting Automation of Excel is where I found this answer. This question is about automation.
Also when a user embeds for example Excel in Word and then edits the embedded Excel the VSTO addin will start multiple times. You can check for the -Embedding arg for this as well.

Typically the ribbon bar is not visible when Office applications are used for rendering documents in the Windows explorer. You may use the following code to check that:
Application.CommandBars("Ribbon").Visible

Related

Creating Word document from Excel Add-In with Office.js

Is it possible to create a .docx file from an Excel Add-In written in office.js?
My use case would be to open an Excel file (on Windows, so the host is an Excel Application), open the Add-In and the Add-In creates a Word document based on data within the Excel file.
From the things that I've seen, it is not possible to call the Word.run() host function from inside a Excel Add-In. I will always get an error that the namespace Word is unknown.
Is this even an intended feature to make 'cross-host calls'?
I had almost the same question: How to get the active PowerPoint presentation from Excel in office.js? and got the answer:
An Office add-in can only work with the Office application (Excel,
Word, PowerPoint, etc.) in which it is open. It cannot reach outside
the Office application to work with a document in another Office
application.
Eventually I moved back to VSTO and C#

CustomUI ribbon customization disappears on save?

I've created an Excel workbook for a client of mine which uses a custom ribbon tab to access the VBA functionality. It thus contains a customUI.xml file with the extra ribbon code in it (by using the Custom UI Editor tool). By now, all was working well for over a year.
However, a few days ago the ribbon customizations keep disappearing after he makes a simple modification to the file and saves it again. Nothing fancy; just change some cell values and ctrl-s save. When opening the saved version the ribbon doesn't show up, and on closer inspection it turns out the ribbon customization is completely gone from the file at that point (the entire root customUI folder is gone and the reference to it from the _rels.rels file is gone too). He's just a regular Excel user, so he doesn't even know about Office custom UI ribbon xmls etc, so it's not that he has been messing with tools he shouldn't have messed with. When I open a working copy of the file on my machine and save it, the ribbon remains in place.
The VBA is still intact though, and the listobject tables that are placed on some sheets are still there too, so it can't be because it got intermediately saved in 2003 format or such...
The file does live in a Sharepoint and OneDrive environment, but IIRC he also had this problem when retrieving a working backup of the file, placing it on his desktop and making a modification from there. Then again a few months ago his IT administrator has moved his company over to Office 356 and migrated his files to the cloud, so it might well be his desktop is on OneDrive too.
What could cause a perfectly fine ribbon to disappear like that? A rogue Office update? Or some Sharepoint 'security' feature to remove ribbons on save? (note that I'm not well known with Sharepoint so this is just wild speculation.) He's using Office 365, so I presume he's on Excel 2019 (as am I).
All leads are welcome, because I'm at a total loss here...

What is the easiest way to add Macro automatically to a set of Excel Files

I have a macro function that I have added to an excel file. My question is how can I add the same macro function to a specific set of excel files without copy pasting the macro in each excel vba editor.What is the easiest way to achieve this?
The objective is for the users who have no knowledge on excel macros should be able to easily add Macros to excel and execute it.
If the people who are importing the macros are also the users of these macros you might want to create an add-in out of your vba macro. The procedure is described here. The users would just have to install the add-in on their PCs once(step 4). They can then use the add-in for several Excel-files.
This needs to be done by each user once:
Step 4: Install the Add-In:
Go to Tools > Add-Ins to open the Add-Ins dialog. If you have stored your Add-In in the default location you will see its name displayed in the Add-Ins available: window (if you have stored your Add-In in a different folder, use the [Browse] button to find it). Click on your Add-In's name to see its description at the bottom of the dialog box.
To install your Add-In place a tick in the check-box next to your Add-In's name and click [OK]. [Click the thumbnail below to see a full-sized image]...
Installing your Add-In (Excel 2002) Installing your Add-In (Excel 2000/97)
As soon as the Add-In is installed its functions will be available in Excel. Find them in the User Defined section of the Function Wizard (Paste Function Tool) or simply type them into a cell as you would any built-in function. The Add-In will remain installed until you return to the Add-Ins dialog and uninstall it by removing the tick from the check-box.

UserForm ActiveX controls not working on new machine

I built a workbook in Excel on my old machine that has a bunch of UserForms in it. One of the UserForms has an ActiveX spreadsheet control in it. This allows me to enter spreadsheet data into the UserForm. My old computer recently crashed so my IT department gave me a new machine that is running the same system (Microsoft Office 2010). Now, when I open the spreadsheet, I get:
Could not load some objects because they are not available on this machine.
I Googled this error and read through a number of pages. The first thing to try was installing Microsoft Office Web Components 11.0. Weirdly, this allows me to add a spreadsheet control to any UserForm I want to but I still cannot open the original sheet with all of its controls still in it.
Next, I tried these instructions but got no results.
Does anybody have any ideas?
Add a reference to Microsoft Forms 2.0 Object Library (found as FM20.dll)
Hth

VBA created with Excel 2003 loaded OK in Excel 2007, but there's nothing in Project tree of VB editor

I have created a VBA in excel 2003 and save it in xla format. This AddIn add a new menu and some submenu in toolbar of Excel. All work well until I upgrade to Office 2007, then I open the xla file. No error message shown, but when I view the macro List, no items there. I open the Visual Basic editor. My old Project (named ML) is still there, but nothing in the Project tree, just default files as when add a new blank project.
I open the xla file with notepad, and my variable, function name are still there. Anyone has experience in this weird behavior, please give me a clue.
Thanks in advance.
Toolbar add-ins generally appear in the add-ins tab of the ribbon in Excel 2007. Make sure you have the add-ins tab displayed (if not you can turn it on under excel options).
If that still isn't working you'll need to go online and read up on altering the code to conform to the ribbon - there are a lot of resources out there should you need to do this.

Resources