Results 1 to 13 of 13
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Attached template (2000 sp-3/ 98SE)

    I'm wanting to create a document from a template, then provide the user with the option of saving in "generic" form, by detaching from the associated template. I was considering using something like:

    ActiveDocument.AttachedTemplate = "C:TemplatesNormal.dot"

    as part of the save. This has the disadvantage of not knowing the location of Normal.dot on the user system. Is there a better way of achieving this?

    Alan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    You can use

    ActiveDocument.AttachedTemplate = "Normal"

    or even

    ActiveDocument.AttachedTemplate = ""

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    Great Hans! That makes things easier (for a nice change! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)

    cheers
    Alan

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    Or (in Word 2002 anyway...) ActiveDocument.AttachedTemplate = NormalTemplate.

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    Thanks Steve!

    Alan

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    OK, I'm still rather stuck here. I'm trying to do this all programatically, so one of the issues is that as soon as I (try to) detach the document from its template, the running code seems to fail or terminate. When I use the code below, then reopen the document, it is still based on the original template. It also appears that the .Saved = True is not happening. Any ideas on a better method appreciated.
    <code>
    Sub SaveUnattached()

    With Dialogs(wdDialogFileSaveAs)
    .Name = GetDV("dvSavePath") & "" & GetDV("dvJobNo") & "_SR"
    If .Show <> 0 Then

    Selection.WholeStory
    Selection.Fields.Unlink
    Selection.HomeKey Unit:=wdLine
    DeleteAllDV

    Application.ScreenUpdating = True
    With ActiveDocument
    .Saved = True
    .AttachedTemplate = ""
    End With

    End If
    End With

    End Sub
    </code>
    Alan

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    You will have to store the code to detach the document from its template in a global template, not in the template you're trying to detach. And since detaching the document from the template counts as a change (as does unlinking the fields) in the document, you must NOT set Saved to True, for the detaching and unlinking would not be saved!

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    I see what you're saying here Hans, and it makes sense. But in the absence of such a global template, which I think would be undesirable, it all seems like a Catch-22. All I can think of is to spawn a new document, based on Normal, copy across what's required, then save that... then somehow get rid of the original document that's no longer needed.

    Alan

    BTW, the ".Saved = True" was an attempt to surpress a Save dialog when the document was ultimately closed.

  9. #9
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    I'm probably not fully understanding what you're trying to do, but for what it's worth, I created a new document based on (and attached to) Tester.dot, put the following Sub in Tester.dot and ran it and ended up with the new document attached to Normal.dot. (Note that I'm using Word 2002.)
    <pre> With ActiveDocument
    .AttachedTemplate = NormalTemplate
    .SaveAs .FullName
    End With</pre>


  10. #10
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    <P ID="edit" class=small>(Edited by AlanMiller on 08-May-05 23:58. Added offending code)</P>Hi Steve

    I tried that route and can certainly change the attached template as you illustrate. Problem is that even though a "SaveAs" is included, this never gets to be executed, because the original attached template, including the running macro, just disappear. This still leads to a "do you want to save changes" on close. If Yes, the Normal template is secured; if No it reverts back to the original.

    I have tried Hans's method with a global add-in, with some very odd results. If I keep using F8 to step through the code, the global sub will run and produce the desired result. Left to its own devices though, the global sub appears not to run at all.

    Alan

    Here is the procedure in the original template:
    <code>
    Sub SaveUnattached()

    Dim strName As String
    strName = GetDV("dvSavePath") & "" & GetDV("dvJobNo") & "_SR"

    Selection.WholeStory
    Selection.Fields.Unlink
    Selection.HomeKey Unit:=wdLine
    DeleteAllDV

    Application.ScreenUpdating = True

    ActiveDocument.SaveAs strName

    Application.Run MacroName:="NormalSave"

    End Sub
    </code>
    Here is the macro in the global template:
    <code>
    Public Sub NormalSave()
    With ActiveDocument
    .AttachedTemplate = ""
    .Save
    MsgBox "Saved"
    End With
    ' *******************
    End Sub
    </code>
    When I step through with F8, execution in the latter begins where the ********** line is marked. I need to F8 again to jump to the start of NormalSave(), then things happen as expected. If I allow things to run automatically, I suspect that End Sub of the latter is all that "happens".

  11. #11
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    Hmmmm, maybe Word 2002 is different than Word 2000 in this regard. When I run the code in my previous post (located in the template that's being detached), the .SaveAs line executes (as does MsgBox "Still running..." if I add that line after the .SaveAs line). If I run the macro and just exit the file, I don't get prompted to save changes, and if I then re-open the file, its attached template has indeed been changed to Normal.

    Or maybe there's something about what DeleteAllDV or your other initial code does that's somehow causing Word to stumble. Have you tried inserting DoEvents before the code that changes the attached template?

  12. #12
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    <P ID="edit" class=small>(Edited by AlanMiller on 10-May-05 01:47. Further info)</P>I've traced through the code I'm using, and it appears that the last line executed in the global macro is
    .AttachedTemplate = ""

    The document is, indeed, then attached to Normal, but unsaved because the .Save line was never executed, hence the prompt to save changes.

    The "DeleteAllDV" function simply deletes all the document variables, and unfortunately the "DoEvents" didn't help. It's puzzling, if a little disturbing, that a macro supposedly independent of the document, would be so affected by changes to the latter.

    Alan

    Edit - It would appear that this represents a bug in 2000 as well as 2002. For 2K, the bug is that the global macro should continue to run; in 2002, it's that the code in the detaching template should cease to run after detachment! For my purposes, I'd rather be stuck with your bug than mine.

  13. #13
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attached template (2000 sp-3/ 98SE)

    Just for the record, I eventually circumvented the Word 2000 problem by creating a second "duplicate" document in VBA, based on Normal, setting it as ActiveDocument, then forcing a close of the original without saving changes. Messy, but it works.

    Alan

Posting Permissions

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