Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Remembering variables? (WinNT/Word97)

    The template I am working on produces documents that can be in one of two states - draft or finalised (yeah, I know, surprise surprise!). However, I need the document to remember what its state is from the previous editing session, without using anything outside of the document.

    Is it possible to set a variable whereby the result will be remembered through the document being closed and reopened (without saving it anywhere outside the document)?

    And if not, can anyone suggest a good method of getting it to remember a simple boolean result? I could use the body of the document as long as it didn't show, since the content is filled in by a userform and otherwise locked so the text cannot be touched by the user in the actual doc ...

    Any help would be appreciated!
    Beryl M


  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    Use document variables.

  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

    Re: Remembering variables? (WinNT/Word97)

    > I could use the body of the document as long

    I'm still proud of my efforts in this area.

    I have devised a scheme whereby I can lodge the DATE of last modification (or any other numeric special key) within the text of the document.

    here's how:

    1) assume that the document has AT LEAST eight space characters (assuming you want to store an eight-digit date).
    2) Collect the first space character; note the size of its font (typically 10 or 12 point, right?)
    3) obtain today's date as an eight-digit formatted string ("20040913", but hurry! this won't last forever .....)
    4) now, heh heh, add the standard point size (eg 12) to each of those eight digits, yielding 14, 12, 12, 16, 12, 21,13, 15 if I've done the sums right.
    5) and now format the first eight space characters (ASCII 032) to be 14, 12, 12, 16, 12, 21,13, 15 points respectively.

    The user will never notice.

    If you were using the date as a key, you can, later, obtain the first eight space characters, obtain their eight point sizes, and subtract the key. The eight results should appear equal in value (e.g. all "10" or all "12")

    I've used this as a means to ascertain that a table of rules for an application is, indeed, a table of rules, by checking that a secret numeric code (might be "5858" or "4166219348") appears up front in the document, cunningly buried in the font size of space characters.

    Try to get some sleep tonight (grin!)



    Here's simple code to effect Custom properties. It will give an Automation error if you try to lock a document twice, but what's life for without finding one hurdle after you've just cleared the "last one", right? The user can change these by (MSWord Menu) File, Properties

    <pre>Public Function DoLockIt(doc As Document)
    doc.CustomDocumentProperties.Add Name:="LockIt", LinkToContent:=False, Value:="True", Type:=msoPropertyTypeString
    End Function
    Sub LockIt()
    Call DoLockIt(ActiveDocument)
    End Sub

    Public Function DoUnLockIt(doc As Document)
    doc.CustomDocumentProperties("LockIt") = "False"
    End Function
    Sub UnLockIt()
    Call DoUnLockIt(ActiveDocument)
    End Sub</pre>


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    How? I am using doc variables to fill in the info, but can they be used as booleans, where they don't have any content and won't show on the page (without displaying as "Error. No document variable ...", as they do when empty)?
    Beryl M


  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    Hi Chris, thanks for that - I think you can be justifiably proud of yourself for such a neat way of hiding a date! I'm going to keep that post for future reference.

    I won't need nearly that much sophistication for this particular project, though - all I need is a simple boolean, and part 2 of your post has given me just what I needed and couldn't think of, a document property! Whether custom or hijacked built-in - whatever! Just you wait until 8am tomorrow - I'm going to whizz through that template now!!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


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

    Re: Remembering variables? (WinNT/Word97)

    > a document property

    Just remember that custom or built-in - the user can destroy your best efforts.


    OTOH, I've always been fond of the LAST paragraph mark in a document, partly because it's "always there" for me, and partly because I feel it's the cause of 50% of my problems - or 90% if we restrict ourselves to computers. KeepWithnext when there is no next seems to be in keeping (sorry!) with the best of MSoft traditions, especially when it can be in one of three states.

    Knock, as they say, yerself out with the other paragraph properties.

    <pre>Public Function LockItUp(prg As Paragraph, blnLockState As Boolean)
    With prg
    .KeepWithNext = blnLockState
    End With
    End Function
    Sub TESTLockItUp()
    Call LockItUp(ActiveDocument.Paragraphs(ActiveDocument. Paragraphs.Count), "True")
    Call LockItUp(ActiveDocument.Paragraphs(ActiveDocument. Paragraphs.Count), "false")
    End Sub</pre>


    ("KeepWithNext : True if all lines in the specified paragraphs remain on the same page when Word repaginates the document. Can be True, False, or wdUndefined. Read/write Long."



    > - all I need is a simple boolean,

    Well, you could always use one of the "features" or Word, and cause them to toggle a single bit in your document. Of course, we know these features better by the name "corruption of document", but still.

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

    Re: Remembering variables? (WinNT/Word97)

    Actually, there's probably a good PhD thesis lurking in here somewhere.

    Suppose you wanted to tag a document with a reminder to do something to/with it after a specific passage of time. We could use the SpaceAfter and Space Before to define a threshold or window of opportunity:
    <pre>Public Function LockItUp(prg As Paragraph, blnLockState As Boolean, sngDaysDelay As Single)
    With prg
    .KeepWithNext = blnLockState
    .SpaceAfter = sngDaysDelay
    End With
    End Function
    Sub TESTLockItUp()
    Call LockItUp(ActiveDocument.Paragraphs(ActiveDocument. Paragraphs.Count), "True", 31.4)
    End Sub</pre>


    Back to Document properties, especially the built-ins: be aware that you need to have a small suite of variable handling routines. As you've probbaly found by now, if you try to Add twice, you'll get an error, and so you need an "IfExists" fucntion to determine whether or not you should add, and so on.

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

    Re: Remembering variables? (WinNT/Word97)

    Chris,

    <hr>True if all lines in the specified paragraphs remain on the same page when Word repaginates the document. Can be True, False, or wdUndefined. Read/write Long."<hr>
    Sounds like a description of KeepLinesTogether to me.

    KeepWithNext causes a paragraph to remain on the same page as the subsequent paragraph, it is a default attribute of headings.

    I can see no reason to use anything other than a DocumentVariable for this particular purpose

    StuartR

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    You can use the document variables to just store the needed info, then have an AutoOpen macro or document_open event do whatever is needed.

  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    Well, that's certainly given me plenty to think about when I get back to work!

    But what I want to know right now is - why do you sign your posts off as 'J' when your name is Christopher Greaves <img src=/S/question.gif border=0 alt=question width=15 height=15> There's nothing in your profile I can see that might explain this either ...?!

    Curiosity killing the cat! <img src=/S/catty.gif border=0 alt=catty width=19 height=18>
    Beryl M


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

    Re: Remembering variables? (WinNT/Word97)

    >you sign your posts off as 'J'

    Because "You furry little bundle of undigested cat-food!" is way too long and "Mister Twisted Whiskers" is just too urbane foir The Lounge. (Jupiter is the one who presses the Enter key; he's not allowed to play with the mouse.)

  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    Ah - this explains much! I remember Jupiter from other posts, I just didn't think of him as being the one to press the enter key!

    Tell him Jinks sends purrs and greetings (as do the others)!

    Oh, and thanks for your help, too!
    Beryl M


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

    Re: Remembering variables? (WinNT/Word97)

    Hi Beryl,

    I would use a CustomDocumentProperty (CDP) to store that status. First a Sub to add such a property. I always use the string-type, so I can use a simple generic Sub with 2 variables. In your case called with AddCPP "Status", "D" (or "Draft")

    Sub AddCDP(vName As Variant, strValue As String)
    ActiveDocument.CustomDocumentProperties.Add Name:=vName, LinkToContent:=False, _
    Value:="D", Type:=msoPropertyTypeString
    End Sub

    You can check the status with If GetValueOfCDP("Status") = "D" Then ...
    (To avoid an error if the CDP does not exist, loop through the collection until CDP found.)

    Public Function GetValueOfCDP(sName As String) As String
    Dim prop As DocumentProperty
    GetValueOfCDP = ""
    For Each prop In ActiveDocument.CustomDocumentProperties
    If UCase(prop.Name) = UCase(sName) Then
    GetValueOfCDP = ActiveDocument.CustomDocumentProperties(prop.Name) .Value
    Exit For
    End If
    Next prop
    End Function

    And you can set the value of a CDP using: SetValueOfCDP "Status", "F" (or "D")

    Public Sub GetValueOfCDP(vName As Variant, sValue As String)
    Dim prop As DocumentProperty
    GetValueOfCDP = ""
    For Each prop In ActiveDocument.CustomDocumentProperties
    If UCase(prop.Name) = UCase(vName) Then
    ActiveDocument.CustomDocumentProperties(prop.Name) .Value = sValue
    Exit For
    End If
    Next prop
    End Sub

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

    Re: Remembering variables? (WinNT/Word97)

    >Sounds like a description of KeepLinesTogether to me

    True. It's a description of a great many properties. Since one could pass a range (of paragraphs) where some of them could be set ON and some OFF, the range would be neither fully-ON nor fully-OFF, in which case it is read as fully-undefined. One can only set True/false, though. Good observation.

  15. #15
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remembering variables? (WinNT/Word97)

    Chris, can you tell me what the status, or type, of a document variable is when it is showing on the screen as "Error! No document variable supplied"? And how to get it to be empty (or 'zero-length') whilst still registering as a text field?

    At the moment, with the error message showing, I keep getting an error that says 'Could not set the Value property. Type mismatch.' when I try to pass the contents of a text field on a userform to be the value of the variable!

    I also need to be able to keep them in position but with no content (ie the options may be to have a sentence in, or not to; it needs to be blank in the latter case).

    I have read through the earlier posts but they seem awfully complicated when all I want to do is pass the info from userform to docvariable!

    <img src=/S/help.gif border=0 alt=help width=23 height=15>
    Beryl M


Page 1 of 2 12 LastLast

Posting Permissions

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