Saving a value in a document

K

Karen

Is there a way to save a value in a document so that it can be read the next time the document is opened?

I have some code that opens an inputbox to get the caption for a photo. The code runs for every photo on the page. I want the user to have the ability to caption a few of the photos, stop that if they wish, even save and close the document. When the document reopens, I'd like to 'read' a value to see where they left off and start from that point.
 
B

Bob

Hi Karen,

Would formatting some text as "hidden" be useful?

Bob
Is there a way to save a value in a document so that it can be read the next time the document is opened?

I have some code that opens an inputbox to get the caption for a photo. The code runs for every photo on the page. I want the user to have the ability to caption a few of the photos, stop that if they wish, even save and close the document. When the document reopens, I'd like to 'read' a value to see where they left off and start from that point.
 
K

Karen

Hi Bob,

Yes, I could do it that way, just looking for a more elegant code way, if possible.

--
Karen
Hi Karen,

Would formatting some text as "hidden" be useful?

Bob
Is there a way to save a value in a document so that it can be read the next time the document is opened?

I have some code that opens an inputbox to get the caption for a photo. The code runs for every photo on the page. I want the user to have the ability to caption a few of the photos, stop that if they wish, even save and close the document. When the document reopens, I'd like to 'read' a value to see where they left off and start from that point.
 
B

Bob

or a custom document property
Hi Bob,

Yes, I could do it that way, just looking for a more elegant code way, if possible.

--
Karen
Hi Karen,

Would formatting some text as "hidden" be useful?

Bob
Is there a way to save a value in a document so that it can be read the next time the document is opened?

I have some code that opens an inputbox to get the caption for a photo. The code runs for every photo on the page. I want the user to have the ability to caption a few of the photos, stop that if they wish, even save and close the document. When the document reopens, I'd like to 'read' a value to see where they left off and start from that point.
 
J

Jay Freedman

Hi, Karen,

Your code can store information in document variables or custom
document properties. Either of them is stored with the document.

Document variables can be created and modified only by code. For
example, to create/set a doc variable named "Fred" to the value
"Flintstone", execute
ActiveDocument.Variables("Fred").Value = "Flintstone"
(Although the Variables collection has an .Add method, you don't have
to use it; setting the .Value will create the variable if it doesn't
already exist.) You can read the value with something like
LastName = ActiveDocument.Variables("Fred").Value
The value can be displayed in the document by a DocVariable field, if
you want that.

Custom document properties can be created and modified by code, or by
the user in the Custom tab of the File > Properties dialog. An example
is
ActiveDocument.CustomDocumentProperties.Add _
Name:="Fred", LinkToContent:=False, Value:="Flintstone", _
Type:=msoPropertyTypeString
and
LastName = ActiveDocument.CustomDocumentProperties("Fred").Value
The value can be displayed in the document by a DocProperty field.
 
K

Karen

Jay,

Thanks a lot. I just didn't even know where to start looking for this.

--
Karen
Jay Freedman said:
Hi, Karen,

Your code can store information in document variables or custom
document properties. Either of them is stored with the document.

Document variables can be created and modified only by code. For
example, to create/set a doc variable named "Fred" to the value
"Flintstone", execute
ActiveDocument.Variables("Fred").Value = "Flintstone"
(Although the Variables collection has an .Add method, you don't have
to use it; setting the .Value will create the variable if it doesn't
already exist.) You can read the value with something like
LastName = ActiveDocument.Variables("Fred").Value
The value can be displayed in the document by a DocVariable field, if
you want that.

Custom document properties can be created and modified by code, or by
the user in the Custom tab of the File > Properties dialog. An example
is
ActiveDocument.CustomDocumentProperties.Add _
Name:="Fred", LinkToContent:=False, Value:="Flintstone", _
Type:=msoPropertyTypeString
and
LastName = ActiveDocument.CustomDocumentProperties("Fred").Value
The value can be displayed in the document by a DocProperty field.
photo. The code runs for every photo on the page. I want the user to have
the ability to caption a few of the photos, stop that if they wish, even
save and close the document. When the document reopens, I'd like to 'read'
a value to see where they left off and start from that point.
 
K

Karen

Hi Bob,

Well, I didn't even know about custome document properties. Thanks for the nudge in that direction.

--
Karen
or a custom document property
Hi Bob,

Yes, I could do it that way, just looking for a more elegant code way, if possible.

--
Karen
Hi Karen,

Would formatting some text as "hidden" be useful?

Bob
Is there a way to save a value in a document so that it can be read the next time the document is opened?

I have some code that opens an inputbox to get the caption for a photo. The code runs for every photo on the page. I want the user to have the ability to caption a few of the photos, stop that if they wish, even save and close the document. When the document reopens, I'd like to 'read' a value to see where they left off and start from that point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top