PDA

View Full Version : Solved: Is There A Better Way to "Store" Procedure Values



MWE
07-23-2008, 01:35 PM
I have a large number of VBA applications that run with target Word files. All VBA code resides in one of the half dozen .dot files in ...Word/STARTUP. I have not used Norrmal.dot becuase of the problems with Normal.dot in Office2000. It has worked out well and keeps the individual .dot files of reasonable size.

Many of these applications have "first time run" information files that are accessed the first time a particular application is run against a target Word file. This information is pulled from xls spreadsheets and the application creates DocumentProperties in the target file. From that point forward, the xls spreadsheet data is not used again with that file. Because this is a one time event, using xls spreadsheets works well and the extra 10 to 20 seconds it takes to create the xls object, etc., is no big deal.

During the conversion process from Office2k to Office03, I have been rethinking how things are done and there are several cases where the xls spreadsheet model is not very efficient. Applications that can be run on any Word file and no doc props are created is a good example. In some of these applications, an xls spreadsheet is accessed the first time the application is run and data is stored in global variables. If Word is shut down and started later, the process is repeated. In the interest of efficiency I played around with "pseudo spreadsheets" to see if I could speed this up. I created a Word file with a half dozen bookmarked tables and stored it in the STARTUP folder. Rather than accessing an xls file, the applications access the word tables file. This is noticeably faster for small tables. For several applications where the amount of data is sucked from a 3 col by 10 row table, there is no perceptable delay.

So, you ask, is there a question after all of this ??

Given what I am trying to do, does anyone have a suggestion for a better way to do it?

macropod
07-23-2008, 04:21 PM
Hi MWE,

Why not store the variables as a comma-delimited string in a simple text file? Then all you need to do is open the files, read in the string and use the Split function to get to whichever variable to want.

As for Normal.dot in Office 2000, I've never encountered any particular issues with it. Having said that, if different projects require different templates, it would seem logical to store any code peculiar to that template in it rather than in Normal.dot.

MOS MASTER
07-23-2008, 05:36 PM
Hi Mark, :hi:

Of course things depend on the amount of data you want to store and the format etc...

Another alternative which is more hidden then the above alternatives is to store the values as metadata in the variables collection of the document.

Like:


ActiveDocument.Variables.Add Name:="Value1", Value:="1"
MsgBox ActiveDocument.Variables("Value1")

HTH

MWE
07-23-2008, 08:21 PM
Hi MWE,

Why not store the variables as a comma-delimited string in a simple text file? Then all you need to do is open the files, read in the string and use the Split function to get to whichever variable to want.Thanks for the reply. For some cases, that is a reasonable approach. But when the data is naturally a table of several cols by many rows, a comma-delimited string is less obvious and IMO more difficult to maintain. But you have gotten me thinking about ways to use Word tables as the information source or maybe go back to the xls spreadsheet, a simple proc to convert that to a comma-delimited string, write that to a text file and then use the text file for future applications. Need to play with that ...

As for Normal.dot in Office 2000, I've never encountered any particular issues with it. Having said that, if different projects require different templates, it would seem logical to store any code peculiar to that template in it rather than in Normal.dot.I originally wanted to use Normal.dot just like one uses Personal.xls (or whatever you choose to call it) in Excel. But I had endless problems with Normal.dot in Word2k. After much complaining (on this forum), more than one person mentioned similar problems and suggested I use Normal.dot as little as possible. As soon as I started using .dot files for vba libraries, all problems disappeared. Of course I am not sure if the recommendations were legitimate or those guys just wanted to shut me up:devil2: That also got me thinking about Personal.xls and I eventually separated most of that into a half dozen separate xla and xls workbooks located in logical directories with links out of XLSTARTUP