Hi Anne,
My question was really, "Is the purpose of the combobox to enable
the user to choose AutoText entries, or are you using AutoText
entries only as someplace to store strings that might be better
stored some other way?" The
point being that AutoText is a great way to store stuff that can
later be inserted into documents, but if you don't need the ability
to keep the formatting with the strings, then there might be other
ways to handle them.
I still can't tell from your latest reply.
However, if you do need AutoText, I'll point out that you do *not*
need to store the data in an INI file or the registry or anywhere
else -- the information is all available from the AutoText entries
themselves. In the procedure that loads the combobox, you can use
something like this:
Dim oAT As AutoTextEntry
For Each oAT In myTemplate.AutoTextEntries
If oAT.StyleName = "RefLine" Then
ComboBox1.AddItem oAT.Name & "|" & oAT.Value
End If
Next oAT
(I'm not sure whether you intend to show the | character in the
combobox, but it can be replaced with a space or other character if
you want.)
If you want to use an external file instead of AutoText, read the
VBA help about the Print # statement and the Line Input statement.
The file can be structured like an INI file, but it doesn't have to
be. The PrivateProfileString method isn't appropriate when you don't
know the names
of the keys in advance.
--
Regards,
Jay Freedman
Microsoft Word MVP
Anne P. wrote:
Jay,
Thanks I will look at the info.
For the last statement, right now I have a few entries in AutoText,
which is really easy to load into a combo box.
Originally, I was saving the Re Lines to an INI file like so
(example of the INI file section):
[ReText]
TimeWarner=TimeWarner Co. v. Cablevision|Case #10456-1045|Other Text
Here IBM Corp.=IBM Corp. v. Fujitsu, Inc.|Case #10545-2045|Other
Text Here
I was able to get them saved into the INI file without a problem
using System.PrivateProfileString. I was also able to get them out
using the same technique, passing the "literal" name of an entry to
System.PrivateProfileString and replacing the pipe characters with a
Soft (or Hard) returns.
However, I need to load a list of the available Re Lines into a
combobox or listbox for the user to choose which one to insert into
the document and that is the part that I can't figure out. I assume
that I need to do an array of some kind to read all the Keys under a
particular section and add them to the array, but I am totally lost.
I would appreciate any help on this that you could offer. I
searched the Web through Google and Ask.com for working with INI
files and could only find very complicated VB6 examples.
I also tried using the Registry to write these values, but had the
same problem. I had no problem getting the entries saved to the
Registry or pulling them back out if I knew the name of the Subkey.
My problem there was the same thing: filling a listbox or combobox
with all of the existing Subkeys.
Thanks,
Anne P.
On Thu, 2 Jun 2005 15:50:29 -0400, "Anne P."
I have a really big problem that I hope someone can help with. I
have a userform that has two textboxes, txtReLine and txtATName.
The user will enter text into the first and a name into the
second. When the user clicks
OK, I need to create an AutoText entry in a template named
Personal.dot in the startup directory. It needs to be under a
category named ReLine, with the name of the entry coming from the
second textbox and the value of the entry coming from the first
box.
All of the information that I can find on creating AutoText shows
it being created from a Selection object or a Range object. Is
there anyway that I can assign the value of the first textbox to a
selection or range object without inserting it into a document
first? This is a routine that will be
used in several templates (letter and memo). I am in a big time
crunch here
and cannot figure out what to do.
I initially thought of using an INI file or the Registry to store
this information, but in all templates that will call the routine,
there is a combo box which has to list the existing Re Line
entries. The only way that
I can figure out how to fill the combo box with those entries is
to use AutoText.
Can this be done, or should I be looking at a different way of
doing it?
Thanks for any help.
Anne P.
You're correct, in order to create an AutoText entry in any
template, the text or other stuff that becomes the entry must
exist in a document first. The Range parameter of the
AutoTextEntries.Add method is a required parameter, and you can't
substitute any sort of in-memory object for it. Further, the
category is specified by the paragraph style applied to that
range; there's no other way to supply the category name or to
change it later.
For code that shows how to load text into a template's AutoText
collection, see the macro in
http://jay-freedman.info/autotextloader2.zip.
Your code could insert the user's text into a scratch document
(which could be hidden behind the active document, or possibly
created with Visible = False although I'm not sure that will
work), apply the ReLine style to it, add it to the AutoText
collection, and then delete the range. There might be some flicker
while that's going on, but it shouldn't be too bad.
Your last comment confuses me, though. Is the stuff listed in the
combo boxes supposed to be a list of the available AutoText
entries, or is it not necessarily AutoText? If not, what else is
it?