Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    word templates (2003)

    I have a template that creates a document. But it now needs to open an existing document and amend that document through variables etc.
    I can get the document to open but am unable to make it the current document for editing purposes even using the .activate
    so what I have is a template that opens as doc 1 and then opens another existing document for editing
    Any clues to make it work

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

    Re: word templates (2003)

    If you want to manipulate the existing document using VBA, you don't need to make it the active document:

    Dim doc As Document
    Set doc = Documents.Open("C:MyDocsExisting.doc")
    ' You can now refer to doc to manipulate it, for example
    doc.Content.InsertAfter "some extra text"

  3. #3
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    Ok that opened the document
    Now here is a question is it possible to save the doc1 created by the template and then continue executing the code to make the second document and then continue to make several different copies of the second document

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

    Re: word templates (2003)

    If the code is in the template, it will stop running the moment you close the new document created from the template.
    You'd have to store the code elsewhere, and create the new document AND open the existing document in the code. The code will then continue to run after saving and closing the new document.
    You can save copies of the second document by using doc.SaveAs "..."

  5. #5
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    That leads to two questions
    1. Where can the code be stored outside the document
    2. would I need therefore to open the first document as I do the second

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

    Re: word templates (2003)

    1. This depends on how you want to use the code. If it's just for yourself, you could store it in your Normal.dot template; it will then be available all the time.
    If other people need to use the code too, you could store it in another template that you and other users copy to their Startup folder for Word; this will make the template into an add-in. Code from an add-in is always available too.
    If the code is needed only occasionally, you could store it in a document; you'd have to open that document in order to run the code.

    2. You can create a new document based on a template using code:

    Dim docNew As Document
    Set docNew = Documents.Add("C:MyTemplatesTemplate1.dot")

    The Add method creates a new document, while the Open method opens an existing document.

  7. #7
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    Thanks

  8. #8
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    Hans
    Is there any way I might send a couple of files as I cannot get this to work at all
    The principle is this The template creates a 4 page document (works fine if you only do one hazard) If you select the next hazard on frmlisthazard.listhhazard the procedure secondsave is started and opens a 2 page document to dump some data to that document (but here it always dumps the data to the first document overwriting it. Then if there are any more hazards on listhazard you run through the second part again until there are no more hazards creating the second document and saving it each time with a different name The second document is called SHHouse.doc .
    John

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

    Re: word templates (2003)

    You can create a zip file with one or more documents. The zip file shouldn't be larger than 100 KB.
    You can attach the zip file to a reply - click the Browse... button below the area where you type the reply.

  10. #10
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    Hi HansZipped its 270k the second doc is 33K I think that what is throwing it all out is the tables here is the second doc . The first document has 5 tables similar to the enclosed doc with two other eables before those in the enclosed document the first being a table with varibles that get populated on running firstsave but they are not needed subsequently when producing the rest ofr the documents.
    The tables with the numbers in are onl;y amemded by changing the border of the sel;ected score or crossed where the score is a national average
    Attached Files Attached Files

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

    Re: word templates (2003)

    I'm sorry, this is not enough information. Could you at least copy the code you're using into a text file and attach that?

  12. #12
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    sorry Hans
    here are the first and second save
    Attached Files Attached Files

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

    Re: word templates (2003)

    Since the code that you're posted calls lots of external procedures, it's difficult to know what exactly it does, but with

    Documents("SHHouse.doc").Activate
    ...
    ...
    ActiveDocument.Close SaveChanges:=wdPromptToSaveChanges

    you're essentially saving SHHouse.doc to itself, not under a new name. You can either use ActiveDocument.SaveAs FileName:="..." where you specify the new name yourself, or let the user specify a name by displaying the Save As dialog:

    Application.Dialogs(wdDialogFileSaveAs).Show

  14. #14
    Lounger
    Join Date
    Oct 2008
    Location
    London
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: word templates (2003)

    will alter and have a go thanks Hans
    Had a go anmd the problem is that the document shhouse never becomes the active document so all the data is saved back to the template document
    The attached is the form that does the work
    John
    Attached Files Attached Files

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

    Re: word templates (2003)

    I'm sorry, I don't have the time or inclination to analyze almost 9,000 lines of code. I hope that someone else will be able to help you.

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
  •