How to perform .Onkey Event in an Excel Add-In created with Visual Studio 2010?

“I would like to run some code when users presses a combination of keys.” Its tricky and to do it without any external dependencies resort to Keyboard hooking to achieve it with a VSTO Excel Add-in: Imports System Imports System.Runtime.CompilerServices Imports System.Runtime.InteropServices Imports System.Windows.Forms Friend Class KeyboardHooking ‘ Methods <DllImport(“user32.dll”, CharSet:=CharSet.Auto, SetLastError:=True)> _ Private Shared … Read more

Detecting text changes in Word 2016 from VSTO add-in

Everthing should work fine if you don’t use a low-level hook in your VSTO add-in. [DllImport(“kernel32”, CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetCurrentThreadId(); const int WH_KEYBOARD = 2; private static IntPtr SetHook(HookProcedure procedure) { var threadId = (uint)SafeNativeMethods.GetCurrentThreadId(); return SetWindowsHookEx(WH_KEYBOARD, procedure, IntPtr.Zero, threadId); } Please note that you probably also need … Read more

How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address

You are using outlook to send the mail. Since outlook must be configured to use the from address of your mail, you cannot provide the from address directly. However, you can select an account available on outlook. For example : using Outlook = Microsoft.Office.Interop.Outlook; Outlook.Accounts accounts = olkApp1.Session.Accounts; foreach (Outlook.Account account in accounts) { // … Read more

Beginning VSTO Development

Yeah, it can get confusing, especially given the skip-level naming conventions, etc. Essentially, you’ll need: Full version (not Express) of Visual Studio and the .NET version you’re targetting. One of the VSTO run times (VSTO 2003, VSTO 2005, VSTO 2005 SE, VSTO 2008, VSTO 2010). For what your asking, VSTO 2005 SE is probably your … Read more

Please explain why I am able to instantiate the “Application” interface in Excel VSTO

The compiler allows you to instantiate interfaces if they’re decorated with a CoClass attribute identifying the concrete class that implements them (as well as a ComImport and a Guid). When you instantiate the interface, you would actually be instantiating this concrete class behind-the-scenes. This “feature” is intended to be used as plumbing for COM imported … Read more