Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving Normal.dot (XP/2000)

    I've got an application in which changes are sometimes made to normal.dot. These changes need to be saved (i.e. I can't just set normal.dot saved=true). However, if the user has normal.dot open (either through Outlook, or through another instance of Word), they will get annoying messages when they close out of my app. For example: "Word cannot save this document because it is open elsewhere." Anybody know a good way to handle this?

    Dan

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving Normal.dot (XP/2000)

    Can you use <font face="Georgia">Application.Templates("Normal.dot") .Save</font face=georgia> to save normal.dot. It seems to work for me.

    StuartR

  3. #3
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Normal.dot (XP/2000)

    Nope, it won't work. To be more precise about the scenario:

    1. I start up Word
    2. I start up my app, which starts up another instance of Word (via: set appWord = new Word.Application)
    3. I then use appWord to load an addin.
    4. I trap Document_BeforeClose events in my addin.
    5. When the Document_Before_Close event sees that the documents collection count = 1, it decides we're done, and tries to save normal.dot. That's when it gets the error.

    Dan

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving Normal.dot (XP/2000)

    What are you saving in Normal.dot? Maybe we can think of an alternative approach for you.
    What call are you making to try and save normal.dot? Maybe we can think of a different call.

    StuartR

  5. #5
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Normal.dot (XP/2000)

    The main thing we're concerned about is formatted autocorrect entries. Normal autocorrect entries get stored in the acl file, but the formatted ones get stored in normal.dot.

    I've tried saving using the same construct as you (application.templates("normal.dot").save, and also using normaltemplate.save. Neither work in the situation I describe.

    Is there a way to determine (a) whether another app has hold of normal.dot, or ([img]/forums/images/smilies/cool.gif[/img] whether normal.dot is "dirty" and needs to be saved?

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving Normal.dot (XP/2000)

    Assuming that you get this error from code as simple as
    <font face="Georgia">If NormalTemplate.Saved = False Then NormalTemplate.Save </font face=georgia>
    then this is going to be difficult.

    Have you tried checking for an existing instance of word and automating that, rather than creating a new one? (See for example the code in <post#=289609>post 289609</post#>)

    StuartR

  7. #7
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Normal.dot (XP/2000)

    Sorry for the delayed response. Went away for a few days.

    It hadn't dawned on me to use the "Saved" property to determine whether the template needed to be saved. So that solves one problem.

    Is there any simple way to determine whether another instance of Word is open just prior to saving the template? Then I could have code like this:

    If Not NormalTemplate.Saved Then
    If MyAppIsOnlyWordInstance Then
    NormalTemplate.Save
    End if
    End If

    That way, I could avoid the error and let Word prompt the person to save the template when they shut down the other instance of Word.

    Dan

  8. #8
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Normal.dot (XP/2000)

    A postscript to my last response: I can't use GetObject on initialization because I want my app running in its own instance.

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Saving Normal.dot (XP/2000)

    > Is there any simple way to determine whether another instance of Word is open just prior to saving the template?

    This seems like something you would need to "ask" the Windows API. For example, you know that every document will have its own entry on the "Applications" tab of the Task Manager dialog. But maybe there will be exactly one instance of WINWORD.EXE on the Processes tab for each actual independent instance of Word? I think that is a hypothesis worthy of exploring. If that works out, you'll probably need some kind of API call to enumerate processes. (I guess. I don't do much in this area.)

  10. #10
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving Normal.dot (XP/2000)

    > That way, I could avoid the error...

    Why not just ignore the error - much simpler.
    <font face="Georgia">
    If Not NormalTemplate.Saved Then
    On Error Resume Next
    NormalTemplate.Save
    On Error GoTo 0
    End If
    </font face=georgia>
    StuartR

  11. #11
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Normal.dot (XP/2000)

    Do you have a suggestion on how can I ignore it? I've tried setting Application.DisplayAlerts = wdAlertsNone, but that doesn't stop the message from popping up.

  12. #12
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving Normal.dot (XP/2000)

    Ah, On Error Resume Next and Application.DisplayAlerts = False doesn't suppress this one then.

    StuartR

  13. #13
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving Normal.dot (XP/2000)

    You can enumerate processes using Word VBAs Application.Tasks collection, but it would take a bit of trial and error to find out what to check for...

    Maybe something like

    For each tskNext in Application.Tasks
    if tskNext.Application = "Microsoft Word" Then...

    StuartR

  14. #14
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Saving Normal.dot (XP/2000)

    I'm getting nonsense results; every task has its .Application and .Parent properties set to Microsoft Word, and the .Creator property is always the same number.
    <pre>Sub TaskCheck()
    Dim tsk As Task
    For Each tsk In Application.Tasks
    If InStr(1, tsk.Application, "word", vbTextCompare) Then
    Debug.Print tsk.Name
    End If
    Next
    If Not (tsk Is Nothing) Then Set tsk = Nothing
    End Sub</pre>

    Also, the Tasks collection doesn't differentiate between two "instances" of Word. (In the attached illustration, the test was tsk.Name rather than tsk.Application.)
    Attached Images Attached Images

  15. #15
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Normal.dot (XP/2000)

    Wow! I never knew that the Application.Tasks collection even existed. Unfortunately the doc for it is misleading. It says: "Returns a Tasks collection that represents all the applications that are running". Depends on how you define "application". It actually appears to return all the Desktop's child window (providing the window has a caption). See the attached, which shows two main subroutines: ShowTasks and ShowDesktopWindows.

    This is all very cool, even if the original problem hasn't quite been solved.
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •