Manipulate Visual Studio from Excel or Word
You can use automation to manipulate various applications, like Word, Excel, Visual Studio, Visual FoxPro
Automation can make many tasks easier, including testing.
You can imagine something like a Word macro that launches Excel to create a concordance of the words in the current Document.
Let’s insert a macro:
Start Excel, choose new document, hit Alt-F11, then Menu->Insert->Module
Paste in this code:
Set ox = CreateObject("Word.application")
ox.Visible = 1
ox.Selection = "Text inserted from Excel"
Now hit F5 to run the macro
You can turn on macro recording and execute a few steps to see what kind of commands are available.
Similarly, you can start Word to create a new document, hit Alt-F11, etc.
You may ask yourself How does this work?
If you start RegEdit you can see the kinds of things you can create (Called Com Servers. You can easily create your own in FoxPro or )
Using Visual Foxpro (which also has an object model and is likewise automatable),
ox = CREATEOBJECT("VisualStudio.Solution")
Try the same code in Excel or Word. (Excel & Word use VBA, which requires the “Set” command when assigning an object to a variable:
Set ox = CreateObject("VisualStudio.Solution")
Set dte = ox.dte
dte.Application.MainWindow.Visible = 1
FoxPro intellisense is nice here because it shows the available members/properties and it shows help information in a tooltip
How did I know this? I wrote the code for FoxPro intellisense.
It used to be I could create “VisualStudio.Application”, but thtat doesn’t seem to work any moer
Does this work from other office applications like Outlook and PowerPoint? Try it and see!
Word Object Model: https://msdn.microsoft.com/en-us/library/kw65a0we.aspx
Excel Object Model: https://msdn.microsoft.com/en-us/library/wss56bz7.aspx
Visual Studio Object Model: https://msdn.microsoft.com/en-us/library/za2b25t3.aspx