[BUG?] DOT Files affected by Addin

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

[BUG?] DOT Files affected by Addin
 
Sven Heitmann




Posts: 193
Joined: 2004-08-23
Hello,

I think there is a Bug in ADX:
When my Addin is installend and activated, and I open a file based on a template/create a new file based on a template and change something, Word is asking me if I want to save changes to the template file too when I close the file!

I think the Commandbars add by ADX are stored inside the dot too!

AFAIK you can specify what document/template is affected when a CommandBar is add.
Best regards,

Sven Heitmann
Posted 05 Oct, 2004 03:55:02 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi,

this dialog can appear when you have the option "Prompt to save Normal template" checked in your Word application. Just check it in the Options dialog box on tab Save.

AFAIK you can specify what document/template is affected when a CommandBar is add.

Word always loads the Normal.dot template when a Word document is opened.
Posted 05 Oct, 2004 07:21:09 Top
Sven Heitmann




Posts: 193
Joined: 2004-08-23
The Dialog I will see is not the Prompt for Normal.dot

This Option is unchecked.

What I get is prompt for is the template my document is based up.
For example I hav a template "Letter.dot" and create a new Document based on it.
When I close the new Document I get the prompt asking me if I want to save changes to "Letter.dot"

Try this:
1. Start Word an unload the AddIn
2. Create a new Template and save it to disk
3. Create a new Document based on the template you have created
4. Save the Document to disk
5. Load your AddIn
6. Open the Document you have created
7. Close the File
8. You should see the Prompt "Do you want to save the changes to the template?"
Best regards,

Sven Heitmann
Posted 05 Oct, 2004 07:58:05 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Sven,

I have a question: does your addin place any controls on built-in command bars?
Posted 05 Oct, 2004 09:26:32 Top
Sven Heitmann




Posts: 193
Joined: 2004-08-23
Yes
Best regards,

Sven Heitmann
Posted 05 Oct, 2004 09:29:43 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
We found out that the dialog appears only when an addin places its controls on built-in command bars. Try to remove these controls to your own command bar. I think the dialog won't show up any more. I suppose it is imposible to change such Word behavior. Unfortunately.
Posted 05 Oct, 2004 09:42:52 Top
Sven Heitmann




Posts: 193
Joined: 2004-08-23
That are really bad news :(
Unfortunately I have the advice to store them there... that are Controls like "Save As"...

However thank you for that info... *going to find a workaround*

edit:
setting temporary to true does not change anything :(

I've testet your suggestion and its working... however that is the last option I would take... damn Word :(
Best regards,

Sven Heitmann
Posted 05 Oct, 2004 09:57:38 Top
Sven Heitmann




Posts: 193
Joined: 2004-08-23
ok, I found a workaround... however I hope it does not effect Word in some other way...

I do need some help in converting it into C#... I think I have to catch some Events from Word too...

This is the VBA Code of the "Workaround"

Sub SetTEmplateSaved()
Application.Templates(ActiveDocument.AttachedTemplate.FullName).Saved = True
End Sub

I tried it and its working fine so far... however I need an event now where it is called...

What do you think about?
Best regards,

Sven Heitmann
Posted 05 Oct, 2004 11:03:12 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
You can put the following code into the DocumentBeforeSave event.

void IWordAppEvents.DocumentBeforeSave(object doc, ref bool saveAsUI, ref bool cancel)
{
Word.Document wd = doc as Word.Document;
object templateName = (wd.get_AttachedTemplate() as Word.Template).FullName;
WordApplication.Templates.Item(ref templateName).Saved = true;
Marshal.ReleaseComObject(doc);
}

See ADX Toys .NET for Word (C#) on our site.
http://www.add-in-express.com/free-addins/net-word-addin.php
Posted 05 Oct, 2004 12:04:46 Top
Sven Heitmann




Posts: 193
Joined: 2004-08-23
Thank you very much... it's working like a charm :)

However I used this code:

Word.Document oDoc = null;
Word.Template oTemplate = null;
try {
    oDoc = doc as Word.Document;
    oTemplate = oDoc.get_AttachedTemplate() as Word.Template;
    //a template has itself attached
    if(oDoc.FullName != oTemplate.FullName) {
        oTemplate.Saved = true;
    }
} catch {}
ReleaseComObject(oTemplate);
ReleaseComObject(oDoc);

in IWordAppEvents.DocumentBeforeClose and IWordAppEvents.DocumentBeforeSave

edit: small bugfix (see comments)
Best regards,

Sven Heitmann
Posted 06 Oct, 2004 02:29:04 Top