Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing Text in a Startup Template (Word XP)

    Hi, all.
    I created and maintain a startup template at the company where I work. I would like to add a nice little maintanence-free utility that would display a summary of each revision in a list-box on a form. (I don't want to have to remember to update the string for this dialog box manually every time I change the template.)

    On the actual template, a la boilerplate text, I have recorded the revision number of the template (e.g. Version 7c) and format it using the Heading 1 style, and immediately after that, I type a summary of the changes for that version. I wrote a little utility that will read each paragraph and format the string to display in the list box, and it works nicely. The problem is that it only reads the text when the template is actually open, as opposed to loaded (because I used the ActiveDocument.Paragraphs collection.)

    So, can anyone tell me a way that I can access the contents/text of the template without actually opening it? I will paste the current code here, but bear in mind that this is the code that only works for when the template is opened using File Open. (Note that I'm checking for styles; this is because the version number is typed and formatted with Heading 1 and the summary of changes is done in the Normal style. Also, in the first For/Next, I assign the template to the variable pDoc, but I don't end up using it because I could only get the code to work using ActiveDocument.)

    <font face="Georgia">Private Sub UserForm_Activate()
    Dim lText As String, pDoc As Template, aTemplate As Template

    lText = ""
    For Each aTemplate In Templates
    StatusBar = aTemplate.Name
    If UCase(aTemplate.Name) = "WPCLITE.DOT" Then
    Set pDoc = aTemplate
    Exit For
    End If
    Next

    For Each tPara In ActiveDocument.Paragraphs
    If tPara.Style = "Heading 1" Then
    lText = lText & "-- " & Left(tPara.Range.Text, Len(tPara.Range.Text) - 1) & " --" & vbCrLf
    Else
    lText = lText & Left(tPara.Range.Text, Len(tPara.Range.Text) - 1) & vbCrLf & vbCrLf
    End If
    Next

    frmVersionInfo.InfoBox.Text = lText

    End Sub
    </font face=georgia>
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    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: Accessing Text in a Startup Template (Word XP)

    Off the top of my head, I can't think of any way to read a document's contents without opening it. It can be opened "not visible," but open I think it must be.

    If you store the strings as document properties, you can read them from a closed file using dsofile.exe, an ActiveX control available from Microsoft.com. However, this is not quite as flexible, obviously, as what you can store in the document body.

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing Text in a Startup Template (Word XP)

    You mention a listbox on a userform, so presumably there are more items on the form and you can't do without the form.
    But I used a different approach for a similar problem with a startup template and maybe you can use this approach. As the text on the template is only visible for those who load it for editing (only me in my case), there's no reason why the template couldn't be protected for forms. So it contains 1 protected (at the top) and 1 unprotected section. In the protected section among other things there's a FormField listbox, and in the unprotcted section there's the information (summary's) to be read. Let your code read the summary's and populate the listbox immediately before saving the new version of the template. That way it will be saved with the template and there's no need to (re)populate it at every time the template is loaded for editing.

Posting Permissions

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