From: LeonidG on 6 May 2010 11:15 I wrote AutoOpen macro that shows or hides the Document Map depending of a document properties. The macro works properly, but now, when I close any document, I get a prompt "Do you want to save the changes..." even if I have changed nothing in the document. I tried to put "ActiveDocument.Saved = True" as the last command of the AutoOpen macro, but it doesn't help. So far I've found a workaround: I put "ActiveDocument.Save" as the last command of the AutoOpen macro. However, the workaround causes updating a document's modified time every time when the document is open. Can anyone suggest a better solution?
From: Rinze Smit on 7 May 2010 13:33 Hi LeonidG Looks like your code changes something else to. As far as I know, showing the Document Map is not a change to the document. Could there be anyting else happening in the code that triggers the change, or do you have fields in the documents that are updated on opening? Greetings, Rinze Smit Revalidatie Friesland
From: LeonidG on 10 May 2010 12:31 Hi, Rinze Here's the code of my macro: Sub AutoOpen() On Error GoTo ErrHandler If ActiveDocument.BuiltInDocumentProperties("Keywords").Value = "SHOWMAP" Then ActiveWindow.DocumentMap = True ActiveWindow.View.ShowHeading 1 Else ActiveWindow.ActivePane.Close End If ActiveDocument.Save GoTo EndOfMacro ErrHandler: If Err.Number = 5867 Then Err.Clear Else MsgBox Err.Description & " " & Err.Number End If EndOfMacro: End Sub I've made some tests and found that my dealing with the document properties triggers the change. So I see two alternative ways: - find another way to recognize a "mapped" document; - clean the flag of changes after it has been set. I've forgot to mention, my version of the Word is 2007
From: Doug Robbins - Word MVP on 10 May 2010 17:46 Another way to recognize a "mapped" document would be to set a document variable in the document to True using ActiveDocument.Variables("Mapped") = "ShowMap" Then for your autoopen macro use: 'Sub AutoOpen() On Error GoTo ErrHandler If ActiveDocument.Variables("Mapped").Value = "ShowMap" Then ActiveWindow.DocumentMap = True ActiveWindow.View.ShowHeading 1 End If ActiveDocument.Save GoTo EndOfMacro ErrHandler: If Err.Number = 5825 Then ActiveDocument.Close GoTo EndOfMacro Else MsgBox Err.Description & " " & Err.Number End If EndOfMacro: End Sub -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "LeonidG" <LeonidG(a)discussions.microsoft.com> wrote in message news:F049EAAF-61FD-4F34-A259-A85258D68E84(a)microsoft.com... > Hi, Rinze > > Here's the code of my macro: > > Sub AutoOpen() > On Error GoTo ErrHandler > If ActiveDocument.BuiltInDocumentProperties("Keywords").Value = > "SHOWMAP" Then > ActiveWindow.DocumentMap = True > ActiveWindow.View.ShowHeading 1 > Else > ActiveWindow.ActivePane.Close > End If > ActiveDocument.Save > GoTo EndOfMacro > > ErrHandler: > If Err.Number = 5867 Then > Err.Clear > Else > MsgBox Err.Description & " " & Err.Number > End If > EndOfMacro: > End Sub > > I've made some tests and found that my dealing with the document > properties > triggers the change. So I see two alternative ways: > - find another way to recognize a "mapped" document; > - clean the flag of changes after it has been set. > > I've forgot to mention, my version of the Word is 2007 >
From: LeonidG on 11 May 2010 01:58 Doug, many thanks. With a document variable it works much better. Here's my final code: Sub AutoOpen() On Error GoTo ErrHandler ActiveWindow.DocumentMap = True If ActiveDocument.Variables("Mapped").Value = "ShowMap" Then ActiveWindow.View.ShowHeading 1 End If GoTo EndOfMacro ErrHandler: If Err.Number = 5825 Then Err.Clear ActiveWindow.ActivePane.Close Else MsgBox Err.Description & " " & Err.Number End If EndOfMacro: End Sub
|
Pages: 1 Prev: VBA Code Cleaner Next: COleException 0x80010105 MSWord Automation |