none
Basic queston on automatic document creation RRS feed

  • Question

  • Hi All appolgies in advance for asking a basic question, What I am trying to do is creat a merge document from 'n' files. So far I can manually insert the files at the required points in a template by using  a series of similiar macros

    "Selection.InsertFile FileName:= _
            //Docs/Build/cover%20letter.doc" _
            , Range:="", ConfirmConversions:=False, Link:=True, Attachment:=False"

    1st question to get each of the files  to insert at the required place is the best method to add a series of bookmarks in the template then add a goto or similiar statement to each macro?

    2nd question by setting Link to true as above I can import the files by reference, which means I can build the complete document once manualy (write protect) then simply apply 'update field' (updaty all?) to each insert to get an updated document. Is this the easiest solution or run the macros onLoad (as in '1') if there is such an event?

    Wider pictcure  I have 20 fies in a SharePoint Libray If the file is selected by an infopath form I intend to write/overwrite the relevent file referenced in '2', if not selected write a blank file to the relevent files. Running a search and replace to replace 2 EoLs with a singe Eol if necessary. I don't even know if this is possible.

    Wednesday, December 15, 2010 3:19 PM

Answers

  • I cannot help you on the last part of your questions, but re the first part, instead of using the Selection object, use the Range of the bookmark.  Then you do not need to move to each bookmark to insert the corresponding file into it

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Acolwknt" wrote in message news:e30708a6-fa8a-49cc-887a-f7174fc49a76@communitybridge.codeplex.com...

    Hi All appolgies in advance for asking a basic question, What I am trying to do is creat a merge document from 'n' files. So far I can manually insert the files at the required points in a template by using  a series of similiar macros

    "Selection.InsertFile FileName:= _
            //Docs/Build/cover%20letter.doc <http://Docs/Build/cover%20letter.doc>;" _
            , Range:="", ConfirmConversions:=False, Link:=True, Attachment:=False"

    1st question to get each of the files  to insert at the required place is the best method to add a series of bookmarks in the template then add a goto or similiar statement to each macro?

    2nd question by setting Link to true as above I can import the files by reference, which means I can build the complete document once manualy (write protect) then simply apply 'update field' (updaty all?) to each insert to get an updated document. Is this the easiest solution or run the macros onLoad (as in '1') if there is such an event?

    Wider pictcure  I have 20 fies in a SharePoint Libray If the file is selected by an infopath form I intend to write/overwrite the relevent file referenced in '2', if not selected write a blank file to the relevent files. Running a search and replace to replace 2 EoLs with a singe Eol if necessary. I don't even know if this is possible.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Bessie Zhao Thursday, December 23, 2010 9:57 AM
    Wednesday, December 15, 2010 11:27 PM
  • Hi Acolwknt

    <<2nd question by setting Link to true as above I can import the files by reference, which means I can build the complete document once manualy (write protect) then simply apply 'update field' (updaty all?) to each insert to get an updated document. Is this the easiest solution or run the macros onLoad (as in '1') if there is such an event?

    Wider pictcure  I have 20 fies in a SharePoint Libray If the file is selected by an infopath form I intend to write/overwrite the relevent file referenced in '2', if not selected write a blank file to the relevent files. Running a search and replace to replace 2 EoLs with a singe Eol if necessary. I don't even know if this is possible.>>

    I'm not sure I understand your second question completely. You're so familiar with what you want to do your mind is taking some short-cuts and I'm not sure if I'm interpreting correctly :-)

    Certainly, if you insert documents as you describe you're creating InsertText fields in the document that maintain links to the original files. Document.Content.UpdateFields should update these. (Actually, Word can be set to update automatically when documents are opened, but due to security concerns, this no longer works as reliably as it once did.) The code can be placed in an AutoOpen and/or AutoNew macro (depending on when and under which circumstances it should execute).

    Note: I'm not familiar enough with SharePoint to be able to say whether links to files on Sharepoint will update the same way I'm used to. You'll need to test that.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Thursday, December 23, 2010 9:57 AM
    Thursday, December 16, 2010 7:23 AM
    Moderator

All replies

  • I cannot help you on the last part of your questions, but re the first part, instead of using the Selection object, use the Range of the bookmark.  Then you do not need to move to each bookmark to insert the corresponding file into it

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Acolwknt" wrote in message news:e30708a6-fa8a-49cc-887a-f7174fc49a76@communitybridge.codeplex.com...

    Hi All appolgies in advance for asking a basic question, What I am trying to do is creat a merge document from 'n' files. So far I can manually insert the files at the required points in a template by using  a series of similiar macros

    "Selection.InsertFile FileName:= _
            //Docs/Build/cover%20letter.doc <http://Docs/Build/cover%20letter.doc>;" _
            , Range:="", ConfirmConversions:=False, Link:=True, Attachment:=False"

    1st question to get each of the files  to insert at the required place is the best method to add a series of bookmarks in the template then add a goto or similiar statement to each macro?

    2nd question by setting Link to true as above I can import the files by reference, which means I can build the complete document once manualy (write protect) then simply apply 'update field' (updaty all?) to each insert to get an updated document. Is this the easiest solution or run the macros onLoad (as in '1') if there is such an event?

    Wider pictcure  I have 20 fies in a SharePoint Libray If the file is selected by an infopath form I intend to write/overwrite the relevent file referenced in '2', if not selected write a blank file to the relevent files. Running a search and replace to replace 2 EoLs with a singe Eol if necessary. I don't even know if this is possible.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Bessie Zhao Thursday, December 23, 2010 9:57 AM
    Wednesday, December 15, 2010 11:27 PM
  • Hi Acolwknt

    <<2nd question by setting Link to true as above I can import the files by reference, which means I can build the complete document once manualy (write protect) then simply apply 'update field' (updaty all?) to each insert to get an updated document. Is this the easiest solution or run the macros onLoad (as in '1') if there is such an event?

    Wider pictcure  I have 20 fies in a SharePoint Libray If the file is selected by an infopath form I intend to write/overwrite the relevent file referenced in '2', if not selected write a blank file to the relevent files. Running a search and replace to replace 2 EoLs with a singe Eol if necessary. I don't even know if this is possible.>>

    I'm not sure I understand your second question completely. You're so familiar with what you want to do your mind is taking some short-cuts and I'm not sure if I'm interpreting correctly :-)

    Certainly, if you insert documents as you describe you're creating InsertText fields in the document that maintain links to the original files. Document.Content.UpdateFields should update these. (Actually, Word can be set to update automatically when documents are opened, but due to security concerns, this no longer works as reliably as it once did.) The code can be placed in an AutoOpen and/or AutoNew macro (depending on when and under which circumstances it should execute).

    Note: I'm not familiar enough with SharePoint to be able to say whether links to files on Sharepoint will update the same way I'm used to. You'll need to test that.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Thursday, December 23, 2010 9:57 AM
    Thursday, December 16, 2010 7:23 AM
    Moderator
  • Hi Cindy thank you, as you rightly point out there are some SharePoint issues which I am perusing on the SharePoint forum.  ( http://social.msdn.microsoft.com/Forums/en-CA/sharepointdevelopment/thread/4bebb8e7-579b-429c-bb02-ca12241084bc )
    (By the way I am also carrying out parallel development using DHMTL with server side processing to a shared drive. I will post a link when resolved for those interested and try to restrict this discussion to word issues only.)

    If it helps, The end result is I am trying to produce a series of documents each built from a different selection of  boilerplate building blocks.  AS these building blocks documents will eventually contain fields that are updated by other applications I want my final constructed documents to reimport the referenced files so that they are upto date with the current information.

    I will now build a document template by importing by reference a set of word files, overwrite the files (some with blank files) and then try  Document.Content.UpdateFieds when I open and close the template.

    As I am now building each master document template manually the only reason that I am using macros to import files  is that its the only method I found of importing by files by reference. ('Insert/object/text from file' does not give you the option of importing  by reference) Is there a method of directly importing files by reference without resulting to macros?

    I will now try to write/or find a generic macro that prompts you to browse  for a file to be imported by reference.

    Thursday, December 16, 2010 10:10 AM
  • Thanks Doug.
    Thursday, December 16, 2010 11:18 AM
  • <<As I am now building each master document template manually the only reason that I am using macros to import files  is that its the only method I found of importing by files by reference. ('Insert/object/text from file' does not give you the option of importing  by reference) Is there a method of directly importing files by reference without resulting to macros?>>

    Take a careful look at the "Insert" button in that dialog box. See the little arrow on the right side of it? click that arrow and you get "Insert and link".


    Cindy Meister, VSTO/Word MVP
    Thursday, December 16, 2010 3:26 PM
    Moderator
  • HI Cindy thanks for the hint unfortunately this looks like a SharePoint issue as import text by reference does not work if the files are located in my SharePoint libraries. Strangely enough import picture by reference and import text by reference from a non-SharePoint file works fine. If anybody knows the reason for this inconsistent behaviour or a workaround I would be most grateful
    Tuesday, December 21, 2010 10:06 AM
  • Probably best to ask in a SharePoint forum, as that's where you'll find the specialists.

    By the way, it's "insert with LINK", not "reference". You should try to remember to use that term :-) Otherwise you could confuse people trying to help you, as a "reference" in Word is something else entirely.


    Cindy Meister, VSTO/Word MVP
    Tuesday, December 21, 2010 10:35 AM
    Moderator