ICPooreman
asked on
MSWord VSTO button functionality
I have created a new button which I added to the toolbar in MSWord with C#. Now the functionality I want to give that button is when someone clicks the button I created it will act as if they clicked save and then act as if they had clicked the open button on the toolbar how do I do this?
ex..
void OnClick_Button(Office.Comm andBarButt on ctrl, ref bool cancel)
{
.....
.....
//what can I put to get same effect as the save button being hit
//I've tried calling event handlers directly but it hasn't given me the same effect as hitting the button.
//I've tried calling wordApplication.activeDocu ment.Save( ) but it produces the error "command failed" and gives no other description
.....
}
ex..
void OnClick_Button(Office.Comm
{
.....
.....
//what can I put to get same effect as the save button being hit
//I've tried calling event handlers directly but it hasn't given me the same effect as hitting the button.
//I've tried calling wordApplication.activeDocu
.....
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To get the new file name you can use the property that the Document class has : doc.FullName;
I use the same procedure as above and I didn't get any errors, this is probably because I use VSTO...
But I think you can ignore the error as long as the application continues to run normally, this error may occur because of some serialization methods used by the framework. You can try installing the SP1 for MS Office 2003... it might solve this problem...
Can you put here those warnings?
I use the same procedure as above and I didn't get any errors, this is probably because I use VSTO...
But I think you can ignore the error as long as the application continues to run normally, this error may occur because of some serialization methods used by the framework. You can try installing the SP1 for MS Office 2003... it might solve this problem...
Can you put here those warnings?
ASKER
doc.FullName isn't giving me the new name of what the document is being saved as I'm having the same problem as before.
I believe the error is because C# doesn't want methods to have the same name, I don't know how to get rid of it but I'm sure there must be a way.
Warning 2 Ambiguity between method 'Microsoft.Office.Interop. Word._Docu ment.Close (ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop. Word.Docum entEvents2 _Event.Clo se'. Using method group.
I believe the error is because C# doesn't want methods to have the same name, I don't know how to get rid of it but I'm sure there must be a way.
Warning 2 Ambiguity between method 'Microsoft.Office.Interop.
You can use the filename object that you use as a parameter in the saveas method to know the file name... if you use the save as method...
The first Microsoft.Office.Interop.W
You can use Word.ApplicationEvents4_Do
and ApplicationEvents4_Documen
The warning will probably disappear if you put in the using clause referring to Word interop only:
using Word = Microsoft.Office.Interop.W
using Microsoft.Office.Core;
Hope this helps.
Regards,
Mishu
ASKER
Thanks a lot the reason the filename wasn't changing was an error on my side in my save event handler. This was quite helpful.
ASKER
I did exactly as you wrote but I still get the error "command failed" on the save() and close() calls. What's weird about it is that if I put a try-catch block around it and ignore the errors it does save and close the documents correctly (as far as I can tell). Should I just ignore the errors?? What could they possibly be?? I have event handlers for save and close however I've traced through them and they produce no errors.
Something important is how do I get the new fileName after calling either save() or saveAs(). If I set filename to doc.Name after save() is called the value getting passed in is Document1 (or whatever it was before) not what I save the file as, how do I get that value??
The open works with no errors, but I need to be able to get the fileName to use it.
On a side note this isn't as important, doc.close() produces warnings do you have any idea how to make them go away.