Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomDocumentProperties. (Word97/sr2 et.al.)

    Cover Functions

    As with most utilities, we can devise cover functions that simplify our use of the procedures for most applications.

    Commonly an application will need only one channel of data at any one time. For example, our database testing application will invoke many different user macros (to format and prepare data from fields in tables), but only one user macro will be in control at any time, and each user macro needs only one piece of data, and that a string.

    Thus armed we can declare that (1) we will use the ever-present Normal.dot as a vehicle for our custom document properties (although we could choose another document or template that was always present and (2) we will use a standard identifier "Channel" as the identifier for any channel access and (3) it will be a string variable (Type:= msoPropertyTypeString).

    With these conventions in place, our user, faced with the task of writing several macros, can write the following cover functions:

    <pre>Public Function GetChannel() As String
    ' Cover function for universal access to data communication channels
    If u.ChannelOpen(NormalTemplate, "Channel", msoPropertyTypeString) Then
    GetChannel = u.ChannelGetFrom(NormalTemplate, "Channel", msoPropertyTypeString)
    Else
    GetChannel = ""
    End If
    End Function

    Public Function PutChannel(varValue)
    ' Cover function for universal access to data communication channels
    If u.ChannelOpen(NormalTemplate, "Channel", msoPropertyTypeString) Then
    PutChannel = u.ChannelPutTo(NormalTemplate, "Channel", msoPropertyTypeString, varValue)
    Else
    PutChannel = False
    End If
    End Function

    Sub TEST03()
    If PutChannel("First Value") Then
    MsgBox GetChannel()
    Else
    End If
    End Sub
    </pre>

    Note how, in TEST03, our communication task is simplified.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomDocumentProperties. (Word97/sr2 et.al.)

    I've also discovered that declaring the template as a DOCUMENT can fail, whereas slopping back to Variant does the trick, especially with the Normal template.

    <pre>Sub test()

    'Dim doc As Document ' doesn't work

    Dim doc ' does work

    ' Set doc = ActiveDocument ' previous essay
    ' Set doc = Templates("Normal.dot") ' previous essay

    Set doc = NormalTemplate
    MsgBox doc.CustomDocumentProperties.Count
    doc.CustomDocumentProperties.Add Name:="var1", LinkToContent:=False, _
    Type:=msoPropertyTypeString, Value:="1"
    MsgBox doc.CustomDocumentProperties("var1").Value
    MsgBox doc.CustomDocumentProperties("var1").Delete
    End Sub

    (spurious test, tossed in as a freebie)

    Sub test2()
    Dim i As Integer
    For i = 1 To Documents.Count
    MsgBox i & Documents(i).Name
    Next i
    For i = 1 To Templates.Count
    MsgBox i & " : " & Templates(i).Name & " : " & Templates(i).CustomDocumentProperties.Count
    Next i
    MsgBox Templates("Normal.dot").CustomDocumentProperties.C ount
    End Sub
    </pre>


  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CustomDocumentProperties. (Word97/sr2 et.al.)

    A template is attached (in PKZip25 form) which demonstrates the use of CustomDocumentProperties to effect a bi-directional channel of communication between a user template and an application template.

    Typically the application template will want to communicate data to the user template (commonly Normal.DOT) by an Application.Run command.

    The channel method is powerful, since the first data item passed can be a delimited string specifying a multitude of other channel names.

    You can read the template by just unzipping it.

    If you want to run the sample code you'll need the latest copy of my utility libarary, which can be obtained as UGreaves.dll.


    (2-apr-2002) updated to include simple cover functions)
    Attached Files Attached Files

Posting Permissions

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