Results 1 to 6 of 6
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New Hidden Doc from Template (97SR2)

    This code will create a hidden document in Word97 based on Normal.dot:

    Dim aDoc As Word.Document
    Set aDoc = CreateObject("Word.Document")

    Is there a way to indicate a template other than normal?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    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: New Hidden Doc from Template (97SR2)

    Like so:

    <pre>Dim aDoc As Word.Document
    Set aDoc = Documents.Add(Template:="whatever.dot", _
    NewTemplate:=False, DocumentType:=wdNewBlankDocument, _
    Visible:=False)
    If MsgBox("Show the new document?", vbQuestion + vbYesNo) = vbYes Then
    aDoc.ActiveWindow.Visible = True
    End If</pre>

    at least in 2000...

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: New Hidden Doc from Template (97SR2)

    Jeff,

    Yes, I know, but, alas, not in 97. Your toy box is bigger than my toy box. Waaaa <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: New Hidden Doc from Template (97SR2)

    Do you want to minimise the window or hide the application completely.

    Application.Visible = False ' will hide the application

    ActiveWindow.WindowState = wdWindowStateMinimize 'will minimise the window

    Documents.Add Template:="whatever.dot", NewTemplate:=False 'will create the new file
    ~~~~~~~~~~ edited by author ~~~~~~~~~~
    Creating a new application object should do what you require
    Step through the following to see what happens - you will get a new instance of word if its already running.
    Dim wdApp As Application
    Set wdApp = CreateObject("word.application")
    wdApp.Documents.Add Template:="y:msofficetemplatesVWA Desk NameTag.dot", _
    NewTemplate:=False
    wdApp.Visible = True
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: New Hidden Doc from Template (97SR2)

    Yahooo! Andrew, that's it! <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23>

    I was hung up on the document object and you went up one to the app (from which one may easily go back down to the doc).

    I don't particularly like starting another instance of Word, but in my case, the app is never visible, so who cares.

    While you're on a roll, let me ask this:
    I now want to write to that file and have this technique. Is there a better way:

    set aDoc = wdApp.Activedocument
    aDoc.content = aDoc.content & strNewText
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: New Hidden Doc from Template (97SR2)

    Kevin

    It looks simple enough already so I wouldn't really recommend any changes if adding text to the end of the new document. You could nest the set statement with the add statement eg
    Dim wdApp As Application, aDoc As Document, sTemplate As String
    sTemplate = "y:msofficetemplatesVWA Desk NameTag.dot"
    Set wdApp = CreateObject("word.application")
    Set aDoc = wdApp.Documents.Add(sTemplate, False)
    wdApp.Visible = True
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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