Results 1 to 13 of 13
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Storing info... but not in a document? (Word97/2000)

    I'm developing a little WORD template (one page). Behind the form-fields, some VBA code is running to facilitate input & submission of results. When starting, my AutoOpen reads an external file with a list of names (to a.o. populate a drop-down & some other stuff).

    I want to get rid of the external file but I do not want the list to be in the VBA code (which I keep locked); so I'm looking for a place to store this info (allowing someone to change it if needed - although VBA code to present that in a dialog box might be OK, I can do that). In EXCEL, I'd do it in some sheet (range-)names (which I could even hide)... how would you WORD guru's do this???

    Mind, I thought about a hidden table in the document, there's simply no space for it on my one pager... (unless there are 'tricks')...

    Erik Jan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    I'm not a Word guru by any means, but you may find the following useful.

    You can use document variables or document properties to store information in a document. Document variables can be manipulated in VBA only, so you'd need to provide a user form if you want end users to be able to edit them. Document properties can be viewed and edited in the File/Properties... dialog, custom tab.

    A Document object in VBA has a Variables collection and a DocumentProperties collection; look them up in the help index to learn more about them.

  3. #3
    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: Storing info... but not in a document? (Word97/2000)

    > I thought about a hidden table in the document, there's simply no space for it on my one pager... (unless there are 'tricks')...

    Well, if it's one point tall or hidden inside a tiny frame... Actually, what do you care how much space it takes up? As soon as you populate the drop downs, you could delete the table, no? (Delete it from the "Document1" that the user has created, I mean, not from the template.)

    Tables are nice because they are structured and relatively easy to maintain, and they won't set off any alarm bells or linger as forgettable metadata. However, if you end up using a DocVar or Custom Document Property instead, you can pack your array into a single string using a delimiter that you know will not be in your data. In Word 2000 and higher (VBA 6), as you may know, the Split() method will in one stroke unpack your variable/property into a dynamically sized array of strings. In Word 97 (VBA 5), you'd have to code that yourself. (Or you could use what MS has proposed in Microsoft Knowledge Base Article 188007 - HOWTO: Simulate Visual Basic 6.0 String Functions in VB5 - I didn't read this closely or test it.)

  4. #4
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    Thanks for the tips & hints! Started to use variables just now, seems pretty straightforward... Created 25 different variables i.s.o. putting them all in one string, that works too (might be a little more coding but guess that's all).

    Erik Jan

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    I'm just delving into document variables (excellent article here ) and they seem to offer lots of possibilities. What's the difference/ merits between Document Variables and Custom Document Properties? In what specific contexts might you use the split() function on an extended long single string?

    Alan

  6. #6
    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: Storing info... but not in a document? (Word97/2000)

    > What's the difference/ merits between Document Variables and Custom Document Properties?

    I'm not the best person to answer this. I've never used document variables. Custom Document Properties are exposed and available for the user to see and change, whereas document variables are more invisible. But I don't know of any other advantage of document variables. (Being visible actually is an advantage for debugging!)

    > In what specific contexts might you use the split() function on an extended long single string?

    Split() turns a sting like alpha;beta;gamma into an array, e.g.,

    Dim strArray() as String
    strArray = Split("alpha;beta;gamma", ";")

    Result:
    strArray(0) = alpha
    strArray(1) = beta
    strArray(2) = gamma

    When you need it, you'll know. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    OK, perhaps I should rephrase my query, taking into account what you say regarding "visibility" to the user. I can see the general value of a delimited string, which can be "split" into an array. But where would such a string appear? If it's in the visible document then the docvars are effectively exposed to the user. On the other hand, if it's within the VBA code (which is the only place from which the *actual* docvars can be manipulated) then why bother with a string? Why not simply maintain an existing array or go direct to the variables collection?

    The difficulty with using docvars seems to be (to me) being able to make permanent changes to them, which are retained after the document is closed. To this end, I can only think of what you suggest - storing a "clever" string in the document body. I can't perceive of a method to make permanent changes to the VBA hard coding. Maybe you could place the string in a document field (bookmark?) to obscure it even further?

    Hope I'm making some sense :-)

    Alan

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

    Re: Storing info... but not in a document? (Word97/2000)

    Document variables, and document properties, are stored with the saved document.

    If you create one of these, save the document and exit word then next time the document is opened the values will still be accessible to your VBA code.

    StuartR

  9. #9
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    Thanks Stuart, I obviously misinterpreted what I had been reading :-(
    That said, I'm still curious about the use of the delimited string as a single-entity storage mechanism for numerous docvars. How exactly would it help?

    Alan

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

    Re: Storing info... but not in a document? (Word97/2000)

    A trivial example.

    DocVar1 = Customer13 High StreetToytown555 5555
    DocVar2 = Customer229 Park RoadLondon444 1234

    You could then fetch the variable you need and separate out the records. As Jefferson said earlier, "When you need it, you'll know"

    StuartR

  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    And now I do know [img]/forums/images/smilies/smile.gif[/img]
    I had the whole thing convoluted in my semi-functioning head! I was thinking along the lines of a split() on:

    A4some_pathinits & name

    to produce:
    DocVar_paper = "A4"
    DocVar_SaveTo = "some_path"
    DocVar_author = "inits & name"

    Your usage makes rather better sense [img]/forums/images/smilies/smile.gif[/img]

    cheers

    Alan

  12. #12
    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: Storing info... but not in a document? (Word97/2000)

    To circle back and complete my thought...
    <UL><LI>In your original post you mentioned retrieving data to populate drop-down controls.
    <LI>I think of drop-down lists as containing an arbitrary number of like items.
    <LI>Array variables are nice for populating these kinds of lists, because you can drive a generic For...Next loops automatically from the beginning index to the ending index of the array.
    <LI>As far as I know, neither document variables nor document properties can store an array variable.
    <LI>The Split() function will read a delimited string (either a document variable or document property) into a dynamically sized array variable.
    <LI>Conversely, you can use the Join() function to turn an array into a delimited string.[/list]So that's why I mentioned Split() in the first place. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  13. #13
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing info... but not in a document? (Word97/2000)

    Thanks Jefferson. I didn't post the original query, but I can see where the delimited string docvar and the dynamic array fit in now. I had the (entire) docvar issue bottom-end-up for some reason; left me wishing I'd never heard of docvar's... or Word... or computers... [img]/forums/images/smilies/smile.gif[/img] Glad you experts could steer me back towards the blissful comforts of everyday confusion ;-)

    cheers

    Alan

Posting Permissions

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