Copy Text, Bookmarks, and DocVariables from one document to another RRS feed

  • Question

  • Hello,

    I'm trying to copy all of the text, bookmarks and docvariables from an existing word document into the open word document. 

    The motivation: I am making a template in one document with macros and a ribbon, but it's not complete.  I want other people to start using the template, but then I want an easy way to update their document vba and ribbon if I make changes to the template. My plan was the just make a macro that would copy and paste EVERYTHING from their existing document into my new template when I release updates.  My plan right now is:

    dim avar
    'First copy over all the information
    documents("[OLD DOCUMENT]").range.copy
    'Next copy over the doc variables
    on error goto next
    for each avar in documents("[OLD DOCUMENT]").variables activedocument.variables(
    activedocument.variables.add value:=avar.value 
    next avar
    on error goto 0

    I don't have the exact code since it's not on this network, but that's the basic gist of what it does.  I've been having problems and I'm also worried about copying over ALL the docvatiables.  Are there certain variables (non-user defined) that I don't want to copy over to my new document?


    Tuesday, May 3, 2011 5:56 PM


  • Hi Dan,

    Regarding your last question concerning docvariables that shouldn’t be copied, I would say the answer is no. The docvariables are controlled by your program and other global add-ins that require them … so copy them all is my recommendation.

    Regarding updating your template … if you do not change the template name that is attached to the user’s document, but you do add functionality (new macros or add ribbon UI buttons), by simply replacing the old template with the new template on the user’s machine they will get the new functionality.

    If on the other hand your new changes require a conversion of a user’s existing document then I would write a conversion program which copies the existing document, attaches the current template, and makes any formatting adjustments.

    Finally, I have to admit to making an assumption about your template functions with the user's document, which might invalidate most everything I've listed here.

    Regards, Rich
    Tuesday, May 3, 2011 8:26 PM