Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Create document variable, can't save document (Word97 (NT))

    Hi

    I have a macro that creates a document variable in the active document.

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

    Re: Create document variable, can't save document (Word97 (NT))

    What happens when you try to save the document?

    StuartR

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create document variable, can't save document (Word97 (NT))

    I want to see some code here. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Create document variable, can't save document (Word97 (NT))

    Hi Kevin and Stuart

    I've fixed it (sort of).

    The offending function looks like this
    <pre>Private Function PropertyValue_Get$(MyPropertyName$, _
    MyDocument As Object, _
    MyIsNumeric As Boolean, _
    MyDontAllowNull As Boolean)
    Dim MyPropertyValue$
    '-----------------------------------------------------------------
    If MyIsNumeric = True Then
    On Error GoTo CustomPropertyFailed
    MyPropertyValue$ = Val(MyDocument.CustomDocumentProperties(MyProperty Name$))
    On Error GoTo 0
    If MyDontAllowNull = True Then
    If Val(MyPropertyValue$) = 0 Then GoTo CustomPropertyFailed
    End If
    If Left$(LCase$(MyPropertyName), 15) = "sectionnumberof" Then
    If Val(MyPropertyValue$) > ActiveDocument.Sections.Count _
    Then GoTo CustomPropertyFailed
    End If
    Else
    On Error GoTo CustomPropertyFailed
    MyPropertyValue$ = Trim$(MyDocument.CustomDocumentProperties(MyProper tyName$))
    On Error GoTo 0
    If MyDontAllowNull = True Then
    If MyPropertyValue$ = "" Then GoTo CustomPropertyFailed
    End If
    End If
    PropertyValue_Get$ = MyPropertyValue$
    Exit Function
    '-----------------------------------------------------------------
    CustomPropertyFailed:
    On Error GoTo 0
    MsgBox MyErrorMessage$, , ""
    Stop
    '-----------------------------------------------------------------
    End Function
    </pre>


    And a typical line that calls it is:
    <pre>Script_FM.Caption = PropertyValue_Get$( _
    MyPropertyName:="TitleBarStub", _
    MyDocument:=ActiveDocument, _
    MyIsNumeric:=False, _
    MyDontAllowNull:=True)</pre>


    The function is called in lots of places, but for some reason, it causes the unexpected behaviour in one particular place. I can't for the life of me work out why. But if I replace the above "Script_FM.Caption= ......" with the following, the problem doesn't occur:
    <pre>Script_FM.Caption = Trim$(MyDocument.CustomDocumentProperties("TitleBa rStub"))</pre>


    What confuses me is that it only happens in one place. I've stepped through the function (saving after each step) and the problem doesn't occur till immediately after the function is exited.

    Anyway, the workaround is satisfactory. Thanks for your responses. You both clearly thought it shouldn't be happening, which gave me the confidence to persevere.

    Thanks
    Dale

Posting Permissions

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