How to debug a Word OfficeJs command-only add-in - api

I am trying to write my first JavaScript Word add-in using Visual Studio Code. As a basis I used the Simple Word Add-in example provided by Microsoft. The example puts all JavaScript code in the commands.html file. I would like to put my code in the separate commands.js file, and use the Word Javascript API instead of the Common API. But with most changes Word just does not respond and I can't see what's happening at this stage.
I have installed the Microsoft Office Add-in Debugger Extension for Visual Studio Code. All examples that I have seen are task pane add-ins, and I was able to attach a debugger to those examples. Is there any way to debug a command add-in (without a task pane)?

Unfortunately the Microsoft Office Add-in Debugger Extension for Visual Studio Code will not work for debugging commands. In order to debug commands, your best bet is to upload your add-in manifest to Office Online, view it in Edge or Chrome and use the DevTools (F12). You should be able to add the add-in project source in the DevTools and just set breakpoints in the commands.
If you are running the Edge Chromium (which I don't think you are based on the fact that Microsoft Office Add-in Debugger Extension worked for taskpane add-ins), debugging commands can all be done in VS Code.

Related

VB.Net Word Add-in has automatically installed itself

I am developing an add-in for Word to add ribbon bar functions for our business.
I am developing the add-in in VB.Net using Windows Visual Studio 2017.
The machine is currently a stand-alone machine that is not connected to the main network.
My issue is that for some reason, the add-in seems to have set itself up in such a way that it appears to have already been installed on the system and loads, with the most updated code, if I just start Word normally.
Any development has been done in Debug mode and I have not been re-building the solution in release mode, and yet anything I change and then run/debug updates the code that the add-in appears to be run off when opening Word directly.
If I go through the options --> add-ins and disable the VTSO add-in it just gets enabled again. I don't seem to be able to separate a debug/development section and live code.
Edit from comments: I can accept that the VTSO needs to be installed and registered but having no separation of live code and development code is frustrating. This machine is used by others for other purposes and this includes using Word, and so any old code must be kept as comments that can set back as the working code should I need to leave part way through. I cannot leave anything partially written as any run the debug mode will set the code as live.
What you're experiencing is normal behavior. When you debug, VSTO registers the add-in in the Windows Registry. This is all that's required for the Office application to find and load the add-in when it starts.
If you disable the add-in in Word, it will remain disabled until you again debug the add-in in Visual Studio.
If you share the machine and want to have the add-in under development disabled for other users:
Work with separate user profiles. VSTO registers its add-ins under CurrentUser, not for all users - VSTO isn't designed to register add-ins for the entire machine. OR
Get into the habit of using Visual Studio's Build/Clean Solution functionality when you leave the machine. That unregisters the add-in (until it runs in debug mode again).

Outlook 2016 Add-in not working

I am working on an Outlook add in and it works fine for all the browsers. However it does not work with Outlook 2016. Initially it worked with Mac, but now it doesn't seem to work with either. It seems like the Office.initialize is never called?
I've searched and tried things for hours but nothing works. Comparing my manifest and initialization to others, I seem to have essentially the same code.
I used the yeoman generator and I am using Office UI Fabric React as my framework. Really at a loss at this point, wondering if anyone has any suggestions or a way to see if any errors are thrown in the Outlook Desktop app?
Update
After much searching and trying things, and starting from scratch, it seems that the add-in stops working as soon as I start using the Office-JS API. Specifically I'm getting the userProfile and the to, from, cc fields from the email Office.context.mailbox.item.
Still unable to find a solution.
When using Office-JS APIs, be sure to call those APIs only after Office.initialize has been called.
Beyond that, there are a few options for debugging add-ins in Outlook 2016. The last section on this page describes how to attach the Visual Studio debugger to the process running the add-in. Be sure to enable Script Debugging in IE options.
There also are a couple of newer options for debugging Office add-ins:
Launch the Visual Studio debugger from a task pane (in Outlook, I right-clicked on the task pane to see this option)
On Windows 10, debug using F12 tools (simple to use, and doesn't require Visual Studio)
For an Outlook add-in running in OWA, just open F12 Developer Tools in any web browser.

Visual Studio Tools for Office VSTO "customization assembly could not be found or could not be loaded"

I just installed Visual Studio 2012 Ultimate and I am trying to create a managed code extension project for Excel 2010 (32 bit Office Professional Plus). I have tried using the .NET 4.0 template contained in VS Ultimate for an Excel 2010 workbook. When I create the project everything looks fine until I run it.
Excel opens and I get the error message "The customization assembly could not be found or could not be loaded. You can still edit and save the document. Contact your administrator or the author of this document for further assistance." The details section is blank.
I have tried everything I could think of to figure this out and I have run out of ideas. I removed all addins from Excel except for the VSTO Design-Time Adaptor for Excel. I removed all personal macros. I set every directory I could think of to "trusted" in Excel and lowered the security settings for all options to "enabled (not recommended)". I completely uninstalled Visual Studio and re-installed. There are no errors or warnings showing up in Visual Studio. I also checked to make sure ".NET Programmability Support" was installed for my copy of Microsoft Excel.
I would link my code but I haven't written anything. I can't even get the default template to load when I run the project. A few others at work have the same setup as me and VSTO runs fine for them using the same steps. I even had someone send me a working project but it gives me the same message when I try to run it.
Is there anything else I can check to see where the problem is occurring? I tried setting break points in the project but it is failing before it gets to any of them.
Thanks so much for your help.
I've run into the same problem with Visual Studio 2010.
I isolated the problem to an SSRS reporting link we were trying to run from the add-in. I removed all the reporting stuff (service reference, sub-dirs, etc.) - the add-in runs fine.
We just ran into this and discovered that a method had a system exception that was not handled. It was hard to track down but once the culprit method had an exception handler the customization finished loading properly.

Building/deploying a simple Word addin

I am trying to build a simple addin for Word 2007 using Visual Studio 2010 and .NET 4.0. It's a relatively simple addin, which brings up a save dialog and saves the document as a Word 2003 document.
The addin runs fine in Word under Debug mode, but does not run under Release or when I create a setup project for it. (It does create the registry keys under HKCU\Software\Microsoft\Office\Word\Addins and they look to be correct) I don't get any errors, and the addin isn't listed under the Disabled Addins either.
I tried adding the Addin manually but it says that it isn't a valid addin. The version of Office is 32-bit, running under Windows 7 64-bit.
Or are there even any alternatives to using VSTO (VBA?) that will let me add a tab to the Ribbon?
You can use IRibbonExtensibility interface (http://msdn.microsoft.com/en-us/library/microsoft.office.core.iribbonextensibility.aspx) to avoid using VSTO.

How to deploy an Outlook macro?

I made an Outlook macro. How can I deploy it to use it on some other machine?
Do I follow the same steps I followed on my machine Tools-> Macros-> create new or is there another way to deploy as we do with the vb or C# projects?
No, you don't need to follow the same steps and re-record the entire macro from scratch. You can save the module containing the macro and import it in Outlook on the other machine.
In Outlook's VBA editor, right-click your module > Export File...
Then on the other machine, in Outlook's VBA editor, right-click your project > Import File...
EDIT You say that your Outlook doesn't have VB Editor. Quoting from Outlook help:
you may be running a Microsoft Office
program with the Visual Basic for
Applications (VBA) shared feature disabled.
I don't know what version of Outlook you have, but for 2003:
To re-enable VBA, follow these steps:
1.Run the Office Setup program again. How? Quit all programs.Double-click
the Add/Remove Programs icon in the
Microsoft Windows Control Panel.Do one
of the following: If you installed
your Office program as part of
Microsoft Office, click Microsoft
Office in the Currently installed
programs box, and then click the
Change button.If you installed your
Office program individually, click the
name of your program in the Currently
installed programs box, and then click
the Change button.
2.On the Features to install screen in the Setup program, click the plus sign
(+) next to Office Shared Features.
3.Select Visual Basic for Applications, click the arrow next to
your selection, and then click Run
from My Computer.
Usually outlook macros are only made for personnal use. Distributing them can be hard as it needs too much actions made by the user (add "devoloper" in ribbon, open visual basic editor, import files, enable references, enable security...).
Microsoft wrote:
If you are developing a solution that you intend to distribute to more than a few people, you should convert your VBA code into an Outlook COM or VSTO add-in or an Office add-in for Outlook.
(source: https://support.microsoft.com/en-us/help/290779/managing-and-distributing-outlook-visual-basic-for-vba).
Knowing that, i recommend you to write a VSTO add-in and deploy it using ClickOnce.
You can start by these links:
VSTO
https://learn.microsoft.com/en-us/visualstudio/vsto/getting-started-programming-vsto-add-ins?view=vs-2019
ClickOnce deployment
https://learn.microsoft.com/en-us/visualstudio/vsto/deploying-an-office-solution-by-using-clickonce?view=vs-2019