Getting document name in addin

P

pavan

Hi All,
I'm creating a Word Addin. There is some code that is to be executed
only for some dpecific doucments while the rest of the code is to
executed for all the documents. hence I need to know the name of the
document that is opened.

object oName = applicationObject.GetType().InvokeMember("Name",
BindingFlags.GetProperty, null, applicationObject, null);

I tried the above but it gives me the name of the application (like MS
Excel, MS Word) but not the name of the document.

Any pointers on this will be of gr8 help
Thanks & Regards,
Pavan
 
C

Cindy M -WordMVP-

Hi Pavan,

Hmmm. If you're not familiar with the application you're trying to
automate, it would probably be easier for you to first do the basics
using early binding. With the help of Intellisense that will tell you
which objects you need.

In this case, you're querying an application object. You first need to
declare an object for the document. Then you need to assign it. Only
after you've done that can you retrieve or set properties, or execute
methods on that object.

In this case, it sounds as if you want to work with
Application.ActiveDocument. So you'd need to InvokeMember for
applicationObject on the property "ActiveDocument", assigning it to an
object variable. That object will then be a document and you can use
GetType and InvokeMember on that to get the Name, etc.
I'm creating a Word Addin. There is some code that is to be executed
only for some dpecific doucments while the rest of the code is to
executed for all the documents. hence I need to know the name of the
document that is opened.

object oName = applicationObject.GetType().InvokeMember("Name",
BindingFlags.GetProperty, null, applicationObject, null);

I tried the above but it gives me the name of the application (like MS
Excel, MS Word) but not the name of the document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
P

pavan

Hey Cindy,
Thanks for your reply. I was able to fix my problem by typecasting the
"applicationObject" into "Word.Application" object. then i used the
..ActiveDocument.Name property to get its name.

But now I've a different problem. My add-in has suddenly stopped
working. It is not creating the button anymore. I tried re-installing
the addin several times, but in vain. I also checked if Word has
disabled my addin from help->About->Disabled Items. But there is
nothing there. I check the registry also just to see if the
"LoadBehavior" is set to 2. But it is set to 3.

I dont understand what the problem is. Can you help me out on this?
Regards,
Pavan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top