• Open a Document as a Copy

    Author
    Topic
    #1767832

    I have code (as part of the UserForm_Activate procedure behind a form) which opens a document to read all of the bookmarks in the opened document.

    Application.Documents.Open FileName:=strRequirementsDocument, _
    ReadOnly:=True, _
    AddToRecentFiles:=False

    The problem is, if this document is already open by another user, I get that annoying “Would you like to make a copy?” message, which I would like to avoid. Is there any way to tell Word to open the document as a copy in code?

    The underlying problem, as you probably have divined, is that I want to return the bookmark names (and the text referred to by the bookmark) to the user in a dialog box, allow them to select the bookmark, and display the text referred to by the bookmark in the dialog box. I can send you all of my code if you need to see it to understand me.

    The user selects a bookmark, clicks OK, and an INCLUDETEXT field is inserted in his or her open document, containing the text referred to by the bookmark. This allows cross-references to a published document to be inserted in another document.

    If there is a way to read all of the bookmarks (and the text they refer to) in a document without opening it, that would be VERY cool.

    Or if you know of some other way to insert cross-references between documents, that would help as well.

    Thanks in advance to anyone who reads and responds.

    dkrathbun@hotmail.com

    Viewing 1 reply thread
    Author
    Replies
    • #1776317

      Something to try is to use the Documents.Add to open a copy and read the bookmark names. Make sure you don’t set the link to this temporary file though or the link won’t stay for long.

      Documents.Add Template:=strRequirementsDocument, NewTemplate:=False

      Are you showing the content of each bookmark or just the names? The code sounds very useful and I would be interested in how it turns out. Can you post it when done?

      I suspect you have to open a file in order to read bookmarks and contents and I know of no other way to cross-reference between documents. Perhaps adding cross refs in a Master Document whilst people edit the sub-documents would work but would be fraught with Danger.

      • #1776398

        This is an interesting approach. Having examined the results, it appears to me that this code simply opens a “new” document using the “strRequirementsDocument” as a template.

        Word calls this “Document” & #, where # is the index number corresponding to the number of new documents you have created during this Word session, incremented by one: “Document 2” for example.

        The new document contains all of my bookmarks, which is a good thing.

        Unfortunately, and oddly, the same annoying error message appears if the document is open elsewhere:
        “Would you like to make a freaking copy of the dang document?” (I’m paraphrasing, of course.)

        What would really make my week would be a way to stealthily add a document to the DOcuments collection and read all its bookmarks, WITHOUT opening it.

        Tall order, I know.

        To respond to your last query, yes of course I would be happy to post the results, once I’m done. There is still a bit of work to be done, what with the odd way the INCLUDETEXT field requires me to refer to the cross-referenced document… Take a look at Word’s Help file if you don’t already know what I am speaking of. I’ll probably have to make another post to the lounge to try to work THAT one out… transforming an ActiveDocument.FullPath string to that flaky thing needed by the INCLUDETEXT field… This requires building a string one character at a time, replacing certain characters– on the fly. Something I have little experience with.

        • #1776443

          There’s a FileCopy statement in VB, but this will fall down if the file to be copied is open.

          If you are on Word 2000 (VB6), you may be able to do this using the FileSystemObject.CopyFile method (requires a reference to Microsoft Scripting Runtime library – this also might be available in Word 97, if you have IE 5 installed).

          I’ve just tried the following simple test, and it seems to work fine if the file to be copied is open:

          Sub CopyFileViaFSO()
          Dim objFileSysObj As New FileSystemObject
          objFileSysObj.CopyFile "C:TEMPTestFileToCopy.doc", "C:TEMPTestFileToCopy2.doc"
          End Sub
          
          • #1776460

            I am using Word 97, and I have IE 5.5 installed. When I run your code, I get the following error message:

            User-defined type not defined.

            Is there something else I can do to make this message go away?

            • #1776470

              In the macro editor, click on Tools, References, then scroll down to “Microsoft Scripting Runtime”, and select it.

          • #1776554

            Hello Gary: I’m not sophisticated enough to know exactly how to copy both you and Phil R. at the same time – you know – still trying to get used to this new Board and figure out how do to attachments, graphics, etc.
            And I realize I’m off topic but wanted to say well-deserved on your elevated status! (Both of you – take a bow!)You have both been, and continue to be, a great help to me and I’m sure, many others.
            Cheers

    • #1776553

      A quite different approach would be to make the source document read only (using its attributes). Then you open it as normal, but there is no problem with a number of users opening it at the same time.

    Viewing 1 reply thread
    Reply To: Open a Document as a Copy

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: