Re: Userforms and bookmarks by Doug
Doug
Tue Feb 14 14:45:06 CST 2006
A value can only be assigned to a variable using code. Normally, the user
should not be opening the template. You can put a button on the toolbar
that runs the autonew macro. You can use code such as the following to
populate the controls on the form with the data from the variables when the
user reloads it when they are working in document:
Private Sub UserForm_Initialize()
With ActiveDocument
txtCompany = .Variables("Company").Value
txtProject = .Variables("Project").Value
txtDocNum = .Variables("DocNum").Value
txtRevNum = .Variables("Revision").Value
txtDocTitle = .Variables("DocTitle").Value
End With
End Sub
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Beth Brooks" <BethBrooks@discussions.microsoft.com> wrote in message
news:4B5ACEAE-91E0-4949-8428-9B29CEEA5341@microsoft.com...
> Doug,
>
> Thank you! That worked very well. I have a couple of follow-up questions:
>
> The variables are used in a template. When a user creates a new document
> based on this template, a userform prompts them for the title, code, and
> date. However, when I open the template, I don't get that prompt, so the
> variables have no initial value. I tried setting a value for each of the
> fields, but I must have done it in the wrong place, because it didn't
> work.
> How (more importantly where) do I set an initial value for each variable?
> (BTW, for the short term, I've created a new file based on the template,
> set
> the variable values using the userform, and then saved the resulting
> document
> as a template. But I'd like to know how to fix this issue for the long
> term.)
>
> Second, I'd like to give the users of this template a way to modify the
> values of these three variables at will, in case they typed something
> incorrectly or the information changes. I'd like to put a button on a
> toolbar
> that brings up the userform displayed when a new file is created. Is that
> possible and, if so, how do I do it?
>
> I very much appreciate your help! I'm an editor trying to fill the role of
> a
> developer and I'm in way over my head!
>
> Thanks!
>
> Beth