Results 1 to 8 of 8
  1. #1
    drathbun
    Guest

    Open a Document as a Copy

    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

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Open a Document as a Copy

    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. [img]/w3timages/icons/frank.gif[/img][img]/w3timages/icons/frank.gif[/img] Perhaps adding cross refs in a Master Document whilst people edit the sub-documents would work but would be fraught with Danger. [img]/w3timages/icons/frank.gif[/img]
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    drathbun
    Guest

    Re: Open a Document as a Copy

    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.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Open a Document as a Copy

    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:

    <pre>Sub CopyFileViaFSO()
    Dim objFileSysObj As New FileSystemObject
    objFileSysObj.CopyFile "C:TEMPTestFileToCopy.doc", "C:TEMPTestFileToCopy2.doc"
    End Sub
    </pre>


  5. #5
    drathbun
    Guest

    Re: Open a Document as a Copy

    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?

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open a Document as a Copy

    In the macro editor, click on Tools, References, then scroll down to "Microsoft Scripting Runtime", and select it.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    352
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open a Document as a Copy

    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.
    David Grugeon
    Brisbane Australia

  8. #8
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Toronto, Ontario
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open a Document as a Copy

    <font color=black>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. </font color=black>
    <font color=red><big>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.</font color=red>
    Cheers</big>

Posting Permissions

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