Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Oct 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating WordDoc2 from WordDoc1 data (9a)

    I don't know if this is the right place to post - sorry if it isn't. I don't usually program in Word and I'm having 'great fun' trying to find my way round the object model.

    I have a questionnare (WordDoc1) where data is collected in form fields (text, checkbox and dropdowns) all as named bookmarks. Some sections are created programatically (direct creation or by AutoText) depending on answers given, so the final questionnaire becomes very individual. I need users to create a report (WordDoc2) from the answers.

    I would normally use Access to store the data and write the report from that, but as it will be used by people without Access, it is not an option here. It seemed quite simple: I thought just adding a new doc that could work with the questionnaire data to the project would be a cinch, but it creates a second project and I can't see any easy way. I can't refer to the Document collection number because I don't know if other documents are also open, and I can't see how I can refer to the file as I don't know the directory structure or the names the documents will be saved under.

    Does anybody have any thoughts on any (easy?) ways of achieving this?

    Philip Avery

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Creating WordDoc2 from WordDoc1 data (9a)

    <hr>I can't refer to the Document collection number because I don't know if other documents are also open, and I can't see how I can refer to the file as I don't know the directory structure or the names the documents will be saved under.<hr>
    It should be fairly easy to define a custom document property, and then cycle through the documents collection looking for a document with the correct property name.

    Public Sub ProcessCorrectDocument()
    Dim docNext As Document
    Dim propNext As DocumentProperty
    For Each docNext In Application.Documents
    For Each propNext In docNext.CustomDocumentProperties
    If propNext.Name = "MyPropertyName" Then
    <font color=448800>' This is the document we were looking for</font color=448800>
    End If
    Next propNext
    Next docNext
    End Sub

    StuartR

  3. #3
    New Lounger
    Join Date
    Oct 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating WordDoc2 from WordDoc1 data (9a)

    Thanks, Stuart. I'll play around with this.

    Philip

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Creating WordDoc2 from WordDoc1 data (9a)

    If the user starts the process of creating the report from the first document, you can set a reference to it as follows:

    Dim docAnswers As Document, docReport as Document
    Set docAnswers = ActiveDocument
    Set docReport = Documents.Add("report.dot")

    You then have a very specific way to refer to your documents.

  5. #5
    New Lounger
    Join Date
    Oct 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating WordDoc2 from WordDoc1 data (9a)

    Yes, this works well. Thanks

Posting Permissions

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