5995 word cannot write to file

S

SP

I have created an Word.Addin, in which I had to add two new Buttons in &File menu. Everyting works fine. When I close word and unregister the addin, I can still see the two new buttons that I have created using my AddIn. So in my IDTExtensibility2_OnBeginShutdown routine I had done thi

' Notify the user you are shutting down, and delete the button..
Set MyButton = oHostApp.CommandBars.FindControl(Tag:="Add Document"
MyButton.Delet
oHostApp.Options.SaveNormalPrompt = Fals
oHostApp.NormalTemplate.Sav

When ever I close the last instance of word, then I am promptedwith the following ms
{ Normal.dot was being edited by another word.session. ID you save this document with the original name, you will overwrite any changes made in the other session

Do you want to save the document using the original name anyway

How can I stop from getting this message when I quit word
 
P

Peter Hewett

Hi SP

Just a thought are you releasing your oHostApp object, this has been know to cause
problems.

Also, what your AddIn is doing is potentially damaging to your users Normal template. You
are always saving the template which is dangerous because the user may have made changes
they don't want saved. Not only that but you're changing the "SaveNormalPrompt" setting.
This is pretty nasty thing to do. I would NOT use an AddIn that messed with my system in
such a way.

What you need to do is save and restore the Normal templates Saved state when you AddIn
loads and when it unloads:
Dim boolSaved As Boolean

boolSaved = NormalTemplate.Saved
' Add or remove your buttons (and anything else you do that modifies Normal.dot) here
boolSaved = NormalTemplate.Saved

If you need to change the state of SaveNormalPrompt then you need to restore it's original
value as well. All this is what a well behaved AddIn should do.

HTH + Cheers - Peter
 
S

SP

Peter
In my addin I am adding new menu items in File Menu in IDTExtensibility2_OnStartupComplete. Next in IDTExtensibility2_OnBeginShutdown routine, I try to remove the buttons that I have added using FindControl . But when I unregister the Addin.Dll, I an still see the menu items that I have created

After doing some research this is what I have found in the following article
http://support.microsoft.com/default.aspx?scid=kb;en-us;230876&Product=wrd200

At the very end the article explains how to delete the button and save the word applicatio
oWord.NormalTemplate.Sav

so when unregister the dll, the menu items that I have created are gone. Is there any other better way of doing this
 
P

Peter Hewett

Hi SP

Said <Is there any other better way of doing this>, yes please refer to my original post.
Have you tried adapting it?

For the reasons previously explained saving the users Normal template is *Extremely*
undesirable. I would not use your addin if your did that to me. I don't want some other
piece of software potentially screwing up my Normal template!!!!

HTH + Cheers - Peter
 
S

SP

Peter
Here is the code that I have in my addin startup and shutdown. No matter what I do I still can see the menu items after I unregister the addin dll. Can you please send me some code that works. or let me know what I am doing wrong.

Thanks

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant
Dim oCommandBars As Office.CommandBar
Dim oStandardBar As Office.CommandBa
Dim boolSaved As Boolea

On Error Resume Nex


If oHostApp.Name = "Microsoft Word" The
boolSaved = oHostApp.NormalTemplate.Save
If Not oHostApp.CommandBars.FindControl(Tag:="Add Document") Is Nothing The
Set MyButton = oHostApp.CommandBars.FindControl(Tag:="Add Document"
Els
Set objcmdPopupBar = oHostApp.CommandBars("Menu Bar").Controls("File"

Set MyButton = objcmdPopupBar.Controls.Add(Type:=msoControlButton, Before:=4, Temporary:=True
With MyButto
.Caption = "Add FileNet Document"
.Tag = "Add Document
.Style = msoButtonCaptio
.BeginGroup = Tru
.DescriptionText = "Add Filenet Document
.Enabled = Tru
.OnAction = "!<MyCOMAddin.Connect>
End Wit
End I
boolSaved = oHostApp.NormalTemplate.Save
ElseIf oHostApp.Name = "Microsoft Excel" The
Set objcmdPopupBar = oHostApp.CommandBars("Worksheet Menu Bar").Controls("File"
Set MyButton = objcmdPopupBar.Controls.Add(Type:=msoControlButton, Before:=4, Temporary:=True
With MyButto
.Caption = "Add FileNet Docu" ''& gsFileNetI
.Tag = "Add Document
.Style = msoButtonCaptio
.BeginGroup = Tru
.DescriptionText = "Add Filenet Document
.Enabled = Tru
.OnAction = "!<MyCOMAddin.Connect>
End Wit

End I

Set oStandardBar = Nothin
Set oCommandBars = Nothin
End Su

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant
Dim boolSaved As Boolea
On Error GoTo IDTExtensibility2_OnBeginShutdown_Er

If (oHostApp.Name = "Microsoft Word") The
boolSaved = oHostApp.NormalTemplate.Save
Set MyButton = oHostApp.CommandBars.FindControl(Tag:="Add Document"
If Not MyButton Is Nothing The
MyButton.Delet
End I
'' oHostApp.NormalTemplate.Sav
boolSaved = oHostApp.NormalTemplate.Save

Els
MyButton.Delet
Set MyButton = Nothin
End I

Set oHostApp = Nothin

IDTExtensibility2_OnBeginShutdown_Exit
On Error Resume Nex
'Insert clean-up code..
Exit Su

IDTExtensibility2_OnBeginShutdown_Err
MsgBox "On ShutDown " & Err.Number & Err.DESCRIPTIO
Resume IDTExtensibility2_OnBeginShutdown_Exi

End Su
 
P

Peter Hewett

Hi SP

The code I provide will only help with preserving the "dirtied" status of Normal.dot. You
might try setting the CustomizationContext before you add and delete your buttons:

CustomizationContext = NormalTemplate

Does the button delete code actually run when you unload your AddIn?

HTH + Cheers - Peter
 

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