how do I tell which Office app is being used?

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

how do I tell which Office app is being used?
 
MediaMogul




Posts: 59
Joined: 2009-06-19
In other words, my button is available to both Word and PPT. At the moment, the buttons only paste a picture if I click them in PPT, but not word. This is clear, as this line is fired when the button is pressed:

PowerPoint.Shape shape = PowerPointApp.ActivePresentation.Slides.Item(currentSlide).Shapes.AddPicture(filePath, Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, 5, 5, width, height);

Obviously, this won't do anything in Word. So what sort of if, or case block coiuld I use to determine the current application? Something like:

if(typeOf.currentApp == Word)
{
//do word stuff
}elseif(typeOf.currentApp == PPT)
{
PowerPoint.Shape shape = PowerPointApp.ActivePresentation.Slides.Item(currentSlide).Shapes.AddPicture(filePath, Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, 5, 5, width, height);
}

And what would be the code to put in the Word if, that is equivalent to the PPT if?

Sorry that this is two Q's in one, but they kinda belong together.

Thank you in advance,
David
Posted 26 Oct, 2009 08:33:30 Top
Andrei Smolin


Add-in Express team


Posts: 17113
Joined: 2006-05-11
David,

I've tested the code below in Word and PowerPoint 2007.

object objectWidth = 10;
object objectHeight = 10;
object objectTop = 5;
object objectLeft = 5;
float floatWidth = 10;
float floatHeight = 10;
float floatTop = 5;
float floatLeft = 5;
string filePath = @"d:my.jpg";
object triStateTrue = Office.MsoTriState.msoTrue;
if(this.HostType == AddinExpress.MSO.ADXOfficeHostApp.ohaWord)
{
    object range= WordApp.ActiveWindow.Selection.Range;
    Word.Shape shape = WordApp.ActiveDocument.Shapes.AddPicture(filePath, ref triStateTrue, ref triStateTrue, ref objectLeft, ref objectTop, ref objectWidth, ref objectHeight, ref range);
} 
else if(this.HostType == AddinExpress.MSO.ADXOfficeHostApp.ohaPowerPoint)
{
    PowerPoint.Shape shape = PowerPointApp.ActivePresentation.Slides.Item(1).Shapes.AddPicture(filePath, Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, floatLeft, floatTop, floatWidth, floatHeight); 
}


Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Oct, 2009 09:16:54 Top
MediaMogul




Posts: 59
Joined: 2009-06-19
Thank you Andrei. When I compile the code this line has 'invalid arguments':

Word.Shape shape = WordApp.ActiveDocument.Shapes.AddPicture(filePath, ref triStateTrue, ref triStateTrue, ref objectLeft, ref objectTop, ref objectWidth, ref objectHeight, ref range);

Can you think why?
Posted 26 Oct, 2009 11:26:33 Top
Andrei Smolin


Add-in Express team


Posts: 17113
Joined: 2006-05-11
David,

I've tested the code both with version-neutral interops and with Office 2007 PIAs; it compiles fine for me. Does Intellisense suggests anything about the parameters of the method?

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Oct, 2009 15:26:39 Top