I am having difficulty building what should be a simple VSTO add-in for outlook 2016. All I am looking to do is create a button in the home mail and a contexts button that takes the selected massage and forwards it to a specified address. Forwarding the message is simple I have found several different ways to accomplish that. The problem is getting the buttons to aper exactly where I want them to I have gotten them to show up in different places using the Office Fluent User Interface Control Identifiers but I can not see to get the button to show in the home tab. I was able to accomplish the whole thing with Macros but could not find a good way to deploy that to multiple workstations.
Outlook 2016 VSTO addin Add button to Main Home
File Not Found Error:VSTO code deployed as Azure Web App and accessing the URL from Sharepoint Online Document Library
We have around ~30 Sharepoint 2010 VSTO templates and we want to deploy that as Web App on Azure PAAS such that we can manage it easily.Now we are trying to add this word Template file(.dotx) to sharepoint document library as content type such that if the users opens the document the template can open and user can perform the required action and save it.As we are currently using the path using the Script editor where the .dotx file is present but when we provide it to Sharepoint Online URL it says file not found.So is there a better way to access this .dotx file for our use or there is other way to find the deployed file which we can use.
Another thing is we know we can use Azure File Share/Blob Storage for this as well and it will come with cheaper option but the thought around using web app is for any change or something the deployment can be done at ease also we have a better to manage it.Any recommendation/help for such solution will be helpful.
Excel 2016 creates second Workbook instance on startup
I have an application level Excel add-in in which I want to create some custom cell styles so that all styles are available across versions 2010, 2013 and 2016.
To do this the following method is called from ThisAddIn.cs.
private static void CellLightRed() { // create new style Excel.Office.Interop.Workbook wb = Globals.ThisAddIn.Application.Workbooks.Add(); Excel.Style style = wb.Styles.Add("20% - Accent7"); // color int index = ColorsList._colorsList.Find("Name", "2010 - 20% - Accent2"); style.Interior.Color = ColorsList._colorsList[index].RGB; }
This works fine in Excel 2010 and 2013. However in Excel 2016 I get a second instance of a Workbook when starting Excel.
Is there any way to avoid this second instance?
Thanks for your help.
Regards Don
VBA MsgBox hides under C# Form (TopMost=true)
Hello,
I have problem with Excel VBA MsgBox which hides under my C# Visual Studio Form. Form has TopMost=true, and this can't be different.
From Ribbon I'm calling my Form, there are few buttons which use VBA code for example:
Globals.ThisAddIn.Application.Run("Server.xlsm!GatherIntel");
In VBA there is error handler to show error if anything wrong comes up, but problem comes that VBA MsgBox hides under my c# Form user can't click anything else on Excel or Form. The only buttons can save user from "End Task" is -> "Enter, space or Esc" buttons, that can "silent" press "OK" button.
How can i make VBA MsgBox to be most top?
Application.OnKey
Application.OnKey have 2 parameters, string key and object procedure.. For reactivate short cut must second parameter to be omissed. Parameter is optional but in C# not exist overload of this method and must specified both parameters. I try with Application.OnKey("^s", null) but not working.
Error Managed Debugging Assistant 'DisconnectedContext'
I got the "Managed Debugging Assistant 'DisconnectedContext' " error.
Managed Debugging Assistant 'DisconnectedContext' Message=Managed Debugging Assistant 'DisconnectedContext' : 'Transition into COM context 0xfc94b0 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)). This is typically because the COM context 0xfc94b0 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else. Releasing the interfaces from the current COM context (COM context 0xfc9568). This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.'
The program is reading analyzing about 200 large excel files, generating one output large excel file. So far I was using it on a smaller amount of files, so perhaps it has to do something with larger memory usage. On the other hand the machines I use have 16GB of RAM. While n run time it doesn't look like memory leak. I don't use pointers, or dynamic memory allocations - simply open files, read, write and close.
While I read I can disable the "'DisconnectedContext' " I prefer to understand how to locate the problem and fix it.
The problem occurs on two separated machines.
How can I debug it?
Where to start?
Thank you
Word AddIN - Custom Ribbon XML - Set value in editbox without callback
Hi,
I am searching for a way to set the value of an editbox programatically.
I am using visual studio 2019 - c# - Word AddIn
I added a custom XML Ribbon to my project (i.e. not via the ribbon designer)
MyRibbon XML contains a group like this:
<group id="GrpTime" label="Timeregistration" autoScale="true">
<box id="box4">
<editBox id="LbLTT" onChange="OnChangeTT" />
</box>
</group>
In MyRibbon.cs I can define a callback method that fires.
public string OnChange(Office.IRibbonControl control)
{
// do something
}
In that scenario I the control that calls the method is passed in.
What I would like to do is to set the value in the editBox control programmatically at runtime with a value that is calculated in my code.
When using the designer, the editBox was available by its id and I could say something like
LbLTT.text = "some new value"
But now that I use the custom XML ribbon, I can't access that control directly.
Can anyone explain how the control can be accessed from code (i.e. without the user causing the callback method to fire).
I found a post that looks like my question: https://365concepts.com/2017/07/19/vsto-enabling-ribbon-controls-at-runtime/comment-page-1/?unapproved=106&moderation-hash=277504cbd0f4b0f1af2dafff7b8e5b0f#comment-106
Unfortunately I could not find a way to create a List<IRibbonControl> with all controls in my custom XML Ribon.What is the proper way to go about this?
Any help will be appreciated.
Kind regards,
Niels
How could I make my Ribbon Designer display in my Outlook 365 ProPlus
I need your help. I am new, creating VSTO. I created an add-in, the code work, and it creates my XML, such as I want it. However, the ribbon and the button do not get to show in my outlook.
My Idea is when the user clicks the button on the email selected, it got save into an XML file.
Here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
XMLFileCreation xmlfile = new XMLFileCreation();
Outlook.Explorer currentExplorer = null;
// public ThisAddIn()
//{
//}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
//Globals.Ribbons.Ribbon1.button1.Checked = true;
currentExplorer = this.Application.ActiveExplorer();
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void CurrentExplorer_Event()
{
Outlook.MAPIFolder selectedFolder =
this.Application.ActiveExplorer().CurrentFolder;
try
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{
Object seleObject = this.Application.ActiveExplorer().Selection[1];
Outlook.MailItem mailItem = (seleObject as Outlook.MailItem);
string Subject= mailItem.Subject.ToString();
string TO= mailItem.To.ToString();
string Body=mailItem.Body.ToString();
string SenderEmail=mailItem.SenderEmailAddress.ToString();
string SenderName=mailItem.SenderName .ToString();
xmlfile.CreateXMLFile(Subject, TO, SenderName, SenderEmail, Body);
}
}
catch
{
}
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace OutlookAddIn1
{
class XMLFileCreation
{
public void CreateXMLFile(string Subject, string TO, string SenderName,string SenderEmail,string Body)
{
XmlTextWriter xWrite = new XmlTextWriter("C:\\Users\\xxxxxxxx\\Desktop\\Outloot-Marketing\\Marketing.xml", Encoding.UTF8);
xWrite.Formatting = Formatting.Indented;
xWrite.WriteStartElement("Email");
xWrite.WriteStartElement("TO");
xWrite.WriteString(TO);
xWrite.WriteEndElement();
xWrite.WriteStartElement("FROM");
xWrite.WriteString(SenderName);
xWrite.WriteEndElement();
xWrite.WriteStartElement("SENDER_EMAIL");
xWrite.WriteString(SenderEmail);
xWrite.WriteEndElement();
xWrite.WriteStartElement("SUBJECT");
xWrite.WriteString(Subject);
xWrite.WriteEndElement();
xWrite.WriteStartElement("EMAIL_BODY");
xWrite.WriteString(Body);
xWrite.WriteEndElement();
xWrite.WriteEndElement();
xWrite.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn1
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
// ThisAddIn mainapp = new ThisAddIn();
if (((RibbonToggleButton)sender).Checked)
{
MessageBox.Show("Hello");
}
else
{
MessageBox.Show("Hello from the else");
}
}
}
}
How to create a VSTO for Outlook desktop 365 ProPlus
Hello All,
Do you have a tutorial in how to create a VSTO for Ourlook 365 proplus? No for Outllook 2013 and 2016.
Word VSTO Ribbon DPI scaling artefacts
Hello,
I am using VS2019 - C# - for creating a Word VSTO AddIn. I have created a Ribbon using XML. It looks fine on a HD monitor (scaling = 100%), but the buttons appear in the wrong location on a 4K monitor. I understand that this is a DPI scaling problem.
I have been looking at DPI awareness, but can't find much about how to handle the MS Word Ribbon specifically.
Does anyone know of a code example that properly handles DPI awareness for a Word VSTO AddIn with Ribbon XML.
It would be very nice if Microsoft could include it in this explanation:
https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-your-first-vsto-add-in-for-word?view=vs-2019
or provide a code example here:
https://docs.microsoft.com/en-us/office/client-developer/ddpi/handle-high-dpi-and-dpi-scaling-in-your-office-solution
Kind regards,
Niels van Strien
Addition information: Others also report that at higher DPI settings, a different number of controls can be placed vertically in the ribbon, specifically three at 96 dpi and 2 at 125 dpi and higher. See this post:
https://stackoverflow.com/questions/53652403/three-small-edit-boxes-no-longer-fit-on-the-same-columns
Unfortunately the post doesn't provide a solution. Can it be considered a bug that the VSTO team can fix?
idMso for Outlook 2019 contact card overflow menu
This idMso does not exist in any of the documents provided at https://github.com/OfficeDev/office-fluent-ui-command-identifiers.
Outlook 2019 has a different overflow menu with a different id. I have been searching all day and as yet have been unable to determine the idMso of this menu. What is it? Does anyone have a working extension of the context/overflow menu on the contact card in Outlook 2019?
We have an addin that will add the appropriate idMso to context menus, but it relies on having a prepared static list of idMso strings to generate customUI xml.
Does there exist some way to inspect the idMso values in UI at runtime, or to programmatically list idMsos for controls without knowing them in advance?
Refresh custom tab
Hi there,
I am creating an Excel Addin (Excel 365 and VS 2019). I have a custom ribbon tab in which I am trying to add an info about the Calculation mode.
When first displayed it shows the correct mode but when the user goes to the Formula tab and changes the mode, it doesn't reflect on my custom tab.
I tried using a checkbox and the getPressed callback. Works on the first call but then it's never called again. I also tried a combo with the getText callback. Same outcome.
Anybody knows how I can achieve this?
Thanks.
Jack
<style></style>All shapes is not found in Slide Master after ApplyTemplate in Powerpoint
Hi
Our customer has two Powerpoint templates, one Standard (4:3) and one widescreen (16:9)
We are trying to create a function to switch between the two, but has stuck with a strange problem.
In the templates SlideMaster, we have a CustomLayout called Start on which there is two images with square dimensions.
One is a colored figure and the other on is a logotype.
In the Customlayout we have given them names.
The logotype is called CUSLogosmal in the Standard template and CUSLogobred in the wide template.
Also, the Customlayout has a distinguished name so that we can separate them between the templates.
In the code we first get the name of the new template and the template Customlayout according to a choice in the UI, like this:
tmplPres = pwtApp.Presentations.Open(sizeTemplate, False, True, False) newPresDesign = tmplPres.Designs.Item(0).Name tmplPres.Close()
sizeTemplate is the full name of the template with "the other" dimensions.
We then applies the new template on the active presentation, and adjust the size to the new size, like this,
pres.ApplyTemplate(sizeTemplate) pres.PageSetup.SlideWidth = newSize
Next step is to delete all CustomLayouts in the active presentation that have another name than the one from the new template, like this:
For Each presDesign In pres.Designs If presDesign.Name <> newPresDesign Then presDesign.Delete() End If Next
At this time the presentation consist of the new SlideMaster applied from the new template.
What we realized here was that there where some duplicate images on the Start Customlayout, and that their dimensions where changed and not squared anymore.
We created a cleaning loop to delete all shapes with names that ended with the name we don't want, like this:
Dim chkName As String If newSize = 720 Then chkName = "bred" Else chkName = "smal" End If For Each presLayout As PowerPoint.CustomLayout In presDesign.SlideMaster.CustomLayouts For Each shp In presLayout.Shapes If shp.Name.StartsWith("CUS") Then If shp.Name.ToLower.EndsWith(chkName) Then shp.Delete() End If End If Next Next
When we examine the processed presentation, we find a duplicate logotype with the name CUSLogosmal in the Customlayout.
This image should have been deleted in the cleaning process.
We have logged all existing images in the cleaning process, but the image CUSLogosmal is missing when we run the function, but exist when we later examine the resulting presentation.
Anybody has a clue what is going on here?
Best Regards Peter Karlström Midrange AB, Sweden
Ribbon XML get checkBox.Checked
a button and a checkBox in RibbonXML
want to get the checkBox.Checked when button click is handled in OnAction func.
since the OnAction func is in the "public class Ribbon1 : Office.IRibbonExtensibility" auto generate by vs,
i can't use this.checkBox.Checked to get the value.
it's different from Ribbon Designer, witch auto generate a "partial class Ribbon1 : Microsoft.Office.Tools.Ribbon.RibbonBase".
the value is available in "public partial class Ribbon1" which hold the control checkBox.
is there any way to get checkBox.Checked in other controls callback process?
error when running a published visual studio app
I am using visual studio 2019. The app runs without error when I am in visual studio, but when i published it and installed it on another computer, it gives me the error:
unable to cast COM object of type 'microsoft.office.interop.excel.application class' to interface type 'microsoft.office.interop.excel_application'. This operation failed because the Queryinterface call on the COM component for the interface with IID {000208D5-0000-0000-C000-000000000046} failed due to tyhe following error:Library not registered.(Exception from HRESULT:0x8002801D (TYPE_E_LIBNOTREGISTERED)).
The published version opens and much of the functionality works fine, but operations that involves using Excel functions is where I get the error.
The computer I built the app with has Excel 2007
Any help you can provide will be much appreciated.
All shapes is not found in Slide Master after ApplyTemplate in Powerpoint
Hi
Our customer has two Powerpoint templates, one Standard (4:3) and one widescreen (16:9)
We are trying to create a function to switch between the two, but has stuck with a strange problem.
In the templates SlideMaster, we have a CustomLayout called Start on which there is two images with square dimensions.
One is a colored figure and the other on is a logotype.
In the Customlayout we have given them names.
The logotype is called CUSLogosmal in the Standard template and CUSLogobred in the wide template.
Also, the Customlayout has a distinguished name so that we can separate them between the templates.
In the code we first get the name of the new template and the template Customlayout according to a choice in the UI, like this:
tmplPres = pwtApp.Presentations.Open(sizeTemplate, False, True, False) newPresDesign = tmplPres.Designs.Item(0).Name tmplPres.Close()
sizeTemplate is the full name of the template with "the other" dimensions.
We then applies the new template on the active presentation, and adjust the size to the new size, like this,
pres.ApplyTemplate(sizeTemplate) pres.PageSetup.SlideWidth = newSizeNext step is to delete all CustomLayouts in the active presentation that have another name than the one from the new template, like this:
For Each presDesign In pres.Designs If presDesign.Name <> newPresDesign Then presDesign.Delete() End If Next
At this time the presentation consist of the new SlideMaster applied from the new template.
What we realized here was that there where some duplicate images on the Start Customlayout, and that their dimensions where changed and not squared anymore.
We created a cleaning loop to delete all shapes with names that ended with the name we don't want, like this:
Dim chkName As String If newSize = 720 Then chkName = "bred" Else chkName = "smal" End If For Each presLayout As PowerPoint.CustomLayout In presDesign.SlideMaster.CustomLayouts For Each shp In presLayout.Shapes If shp.Name.StartsWith("CUS") Then If shp.Name.ToLower.EndsWith(chkName) Then shp.Delete() End If End If Next Next
When we examine the processed presentation, we find a duplicate logotype with the name CUSLogosmal in the Customlayout.
This image should have been deleted in the cleaning process.
We have logged all existing images in the cleaning process, but the image CUSLogosmal is missing when we run the function, but exist when we later examine the resulting presentation.
Anybody has a clue what is going on here?
Best Regards Peter Karlström Midrange AB, Sweden
Exception when install Click Once deployment for a Word AddIn
I created a Word 2007 AddIn project in VS 2008 and use VS 2008 publisher to generate click once deployment package.
When I ran the setup.exe generated from publish package on Windows 7 machine, I got exception as follows:
Name:
From:file:///c:/Program Files/MyCompany/Product/Publish/WordAddIn.vsto
Specified cast is not valid.
************* Exception Text ************
System.InvalidCastException. Specified cast is not valid.
at
Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.GetManifests(TimeSpan timeout)
at
Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()
The failure can occur either at first time installation or at re-installation after uninstalling the same AddIn. Also this failure only occurs on Windows 7, not Windows XP.
Any insight on this matter is greatly appreciated.
Insert text at the start of mailitem.Body in VSTO Outlook using C#
Hi all, I am trying to create a plugin for Outlook 365 that whenever a user compose a new mail OR Reply OR Reply To All, automatically some greeting text appears at the starting of new mail message.
I am able to capture all 3 events(New/Reply/Reply All), but whenever inserting text inside the new editor window either the text appends at last of new mail body or all the formatting vanishes.
I am not so much familiar with VSTO, so took reference from Internet and wrote this piece of code :
Outlook.Inspectors inspectors; private Outlook.Application _application = null; Outlook.Explorer currentExplorer = null; private void ThisAddIn_Startup(object sender, System.EventArgs e) { _application = Globals.ThisAddIn.Application; _application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(_application_ItemLoad); inspectors = this.Application.Inspectors; inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { // Note: Outlook no longer raises this event. If you have code that // must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785 } Outlook.MailItem mi = null; private void GenerateItemMessage(object item, string operation) { mi = item as Outlook.MailItem; currentExplorer = this.Application.ActiveExplorer(); currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event); } private void CurrentExplorer_Event() { if (this.Application.ActiveExplorer().Selection.Count > 0) { Outlook.MailItem selObject = this.Application.ActiveExplorer().Selection[1]; if (selObject.BodyFormat == Outlook.OlBodyFormat.olFormatHTML) { string link = "new string" + Environment.NewLine; selObject.HTMLBody = link + selObject.Body; } } } private void ThisAddIn_ReplyAll(object item, ref bool cancel) { GenerateItemMessage(item, "ReplyToAll"); } private void ThisAddIn_Reply(object item, ref bool cancel) { GenerateItemMessage(item, "Reply"); } Outlook.ItemEvents_10_Event _item; private void _application_ItemLoad(object Item) { _item = (Outlook.ItemEvents_10_Event)Item; _item.ReplyAll += new Outlook.ItemEvents_10_ReplyAllEventHandler(ThisAddIn_ReplyAll); _item.Reply += new Outlook.ItemEvents_10_ReplyEventHandler(ThisAddIn_Reply); } void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) { if (greetings.greetingEnabled == true) { Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem; if (mailItem != null && mailItem.EntryID == null) { mailItem.HTMLBody = mailItem.HTMLBody.Insert(0, "Hi"); } } } #region DODMethods string finalGreets(string recievers) { if (recievers is null) return greetings.greetingText + " ," + Environment.NewLine; if (recievers.Split(Convert.ToChar(";")).Length > 1) return greetings.greetingText + " all," + Environment.NewLine; else return greetings.greetingText + " " + greetings.greetingGender + " " + recievers + "," + Environment.NewLine; } #endregion #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion
Method CurrentExplorer_Event() is responsible to add text inside new mail message body(Where I have wrote the above code provided by you).
The issue here is, whenever I try to generate text inside new mail body(Or new mail editor), either it appends to the last or it vanishes the format of whole mail.
I want the new editor opened always with my defined text without modifying any formatting.
I observed one more issue into this, that whenever reply/reply all event occurs, the defined action is performing twice.
Please help me in achieving this task.
Best Regards,
Ankit Singh Rawat
Get editable area of a mail item Outlook 365 VSTO C#
Hi,
How can I get inspector of editable area of Outlook 365 whenever new/reply/reply all event occur?
Also, can I get default signature text?
Regards,
Ankit Singh Rawat
Ribbon Group image
Hi,
Working with VSTO Community 2015 on an Excel Addin. When I reduce the size of the Excel window my custom ribbon groups get the same default icon image: a white square with a green circle (see picture below). How can I change this default icon using
the VSTO Ribbon designer (no xml programming)? Thanks you for your help