+ Reply to Thread
Results 1 to 9 of 9

Inserting word custum template at end of document on new page

  1. #1
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Inserting word custum template at end of document on new page

    Hello!

    I could really use help with macro for inserting template.
    I have a Main word macro file, with 2 front pages and a third page as a template. The document is password protected so the end user can only fill in the yellow marked areas, when they have filled in the 2 front pages and the third template page, and need to insert another 4 page exactly as page no 3. they press short command "Alt + N" as in new page.

    the macro then should insert the new page from the template word file. and put it last, first unlocking the word file, then inserting, then putting the password back on.

    This works fine as long as you are only active with the cursor in the yellow marked areas or at the end of the document. but when you for example ar in the header, or footer. the macro fails and stops when the word file is unprotected. wich is not good.

    Could anyone help me?

    I need it to always abort the current command, jump to last page in document, then unprotect the document, insert the template, and protect the document again. enabling the user to continuing adding information.

    Pardon my english.

    The code i use now is as follows.

    Please Login or Register  to view this content.
    Thanks in advance for any help!
    Last edited by lavinius; 05-20-2013 at 06:43 AM.

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Inserting word custum template at end of document on new page

    Perhaps:
    Please Login or Register  to view this content.
    Last edited by macropod; 05-20-2013 at 07:24 PM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Inserting word custum template at end of document on new page

    Hi

    Thanks for the reply, the code fails with runtime error 438, Object does not support the property or method

    COde stops at .insertfile Filename:="Tabellmall Standard.docm",....

    Cheers

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Inserting word custum template at end of document on new page

    Sorry 'bout that. Try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Inserting word custum template at end of document on new page

    Thanks for all help,

    I really apriciate your time and effort, it feels almost at home,
    Now i get runtime error 5174, Cannot find the file "Tabellmall Standard.docm"

    I the first code i had it tells it to look for the file in the same location as the Main word macro file is located. so both the main file and template ar in the same place. and how ever you move them i want it to always find the file as i always intend to place them together in same folder, wherever that might be

    Thans once again!

    Cheers

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Inserting word custum template at end of document on new page

    There is nothing in the code you posted to tell Word where to look. If it's not finding the file now, I doubt it would have found it before. Furthermore, it can't look in the current document's folder until that document has been saved; until then the document doesn't have a folder to look in! You should add the full path to the document or, if you can be sure the document has already been saved:
    .InsertFile FileName:=ActiveDocument.Path & "\Tabellmall Standard.docm", Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False

  7. #7
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Inserting word custum template at end of document on new page

    Allright, My misstake, Sorry about that, the code you posted works fine after editing the code AND SAVING .

    It now finds the template and inserts it regardless of where im currently editing in the document, I owe you a great deal of thanks
    The origin code i was refering to when locating the doc regardles where i place them as long as the are together is "Dim myDocPath As Selection"?
    Or am i worng? i assumed that the code tells it to look in the current location of the file for the template.

    Anyhow. Problem solved.

    Thanks alot m8!!

    Cheers

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Inserting word custum template at end of document on new page

    Although there was a "Dim myDocPath As Selection" in the code you posted, I can't see how that could possibly return a file path unless some content in the document equating to a file path was selected when the code was run. As it is, your code made no use of that variable, for which I'd have expected to see something like:
    Please Login or Register  to view this content.
    Last edited by macropod; 05-21-2013 at 05:55 AM.

  9. #9
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Inserting word custum template at end of document on new page

    Ah allright, i think i understand

    Once again, i thank you alot for the help! stuff u gave works perfect and as intended.

    Have a wonderful day!

    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1