Neutral ActiveDocument Object?

Add-in Express™ Support Service
That's what is more important than anything else

Neutral ActiveDocument Object?
 
Mark De Lorenzo




Posts: 40
Joined: 2015-06-22
My Office Add-In is active in multiple Office Apps. But if I need to address particular attributes, or execute particular methods for the ActiveDocument, I have to first determine which application I'm currently in.

I find myself creating "Select Case" frequently.

Select Case Me.HostName
   Case "Microsoft Word"
      DocSaved = WordApp.ActiveDocument.Saved
      WordApp.ActiveDocument.Save()
    Case "Microsoft Excel"
      DocSaved = ExcelApp.ActiveDocument.Saved
      ExcelApp.ActiveDocument.Save()
    Case "Microsoft PowerPoint"
      DocSaved = PowerPointApp.ActivePresentation.Saved
      PowerPointApp.ActivePresentation.Save()
    Case "Microsoft Visio"
      DocSaved = VisioApp.ActiveDocument.Saved
    Case "Outlook", "Microsoft Access", "Microsoft Publisher"
      ' Button not enabled for these applications
End Select


Not a practical piece of code, but I'm simply making a point between the properties and methods of the application objects.

Is there a way to obtain the ActiveDocument properties and methods regardless of the current office application?
Posted 11 Jan, 2018 07:55:17 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Mark,

There's no common class that you could use. If all (or most) of the Application types above have a property (or method) of the same name, you can use late binding; see System.Type.InvokeMember().


Andrei Smolin
Add-in Express Team Leader
Posted 11 Jan, 2018 09:30:41 Top
Mark De Lorenzo




Posts: 40
Joined: 2015-06-22
Thank you for the direction Andrei
Posted 11 Jan, 2018 09:47:17 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 11 Jan, 2018 09:52:22 Top