MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 20th, 2002, 07:37 PM   #1
jkpd2000
 
Join Date: May 2002
Posts: 91
Default

I want to store a value in my VBA script in some place say a variable. i will be incrementing that and storing the value in the next run. is it possible?
jkpd2000 is offline   Reply With Quote
Old May 20th, 2002, 08:13 PM   #2
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 3,863
Default

Hello jkpd2000,

There is no way I know of to store data in a VBAProject. However, you can store data in a workbook in an Excel Name object, and you can also store data in a CustomDocumentProperty object. Say the value you want to store is a version number, like 7. To store the data in a Name object:

Names.Add Name:="VersionNumber", RefersTo:=7

and to change it:

Names("VersionNumber").Value = 8

This has the advantage that the name can be referred to in a cell formula (i.e., =VersionNumber will yield 8 in the cell)

Similarly, to create a new CustomDocumentProperty:

ThisWorkbook.CustomDocumentProperties.Add _
Name:="Version Number", _
LinkToContent:=False, _
Type:=msoPropertyTypeNumber, _
Value:=7

and to change it:

ThisWorkbook.CustomDocumentProperties("Version Number").Value = 12

This has the advantage of being viewable outside of Excel by the File Explorer and searchable outside of Excel using the Advanced Find.



__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other lives: http://members.tripod.com/playitagaindamon ,
http://community.webshots.com/user/piadamon )
Damon Ostrander is offline   Reply With Quote
Old May 20th, 2002, 08:15 PM   #3
zacemmel
 
zacemmel's Avatar
 
Join Date: Apr 2002
Location: Redmond, WA
Posts: 636
Default

Another way you can do this is use the wonderful thing in Windows called the registry Of course it might be a pain to write registry values just for one variable, but it can come in handy sometimes. There are just a few API calls you have to make in order to do this. Simple, really.

[ This Message was edited by: zacemmel on 2002-05-20 14:16 ]
zacemmel is offline   Reply With Quote
Old May 20th, 2002, 09:02 PM   #4
stevebausch
 
Join Date: May 2002
Posts: 809
Default

SaveSetting, GetSetting



You don't need no stinkin API calls
stevebausch is offline   Reply With Quote
Old May 20th, 2002, 09:03 PM   #5
zacemmel
 
zacemmel's Avatar
 
Join Date: Apr 2002
Location: Redmond, WA
Posts: 636
Default

If you want them in custom folders in the registry, yes, you do need API calls.
zacemmel is offline   Reply With Quote
Old May 20th, 2002, 09:11 PM   #6
jkpd2000
 
Join Date: May 2002
Posts: 91
Default

hi damon,

i used the 2nd version of your code. how to find it outside of excel. will it be a saved as a file ? if so can you tell me how to find
jkpd2000 is offline   Reply With Quote
Old May 21st, 2002, 04:07 AM   #7
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 3,863
Default

Hi again jkpd2000,

The value is actually stored internally to the workbook, but is nevertheless accessible without having to open the workbook. For example, if you right-click on the workbook file in the file explorer and select Properties, then go to the Custom tab, you will see the new Version Number custom property displayed there.

There used to be an Office Find File utility that would enable one to search for files with certain document property values, but it is no longer provided with Office as a separate utility. This capability has been built into the Office application (including Word, PowerPoint, Access, etc.) Open menu advanced search capability, but will not let you search for Custom property values, only standard built-in DocumentProperty values.

I believe that there is a Windows API routine that also allows you to access the document properties, including custom document properties, without opening the file. One advantage with this is that this would enable certain properties of a file to be accessed even if the file contains macros without having to enable macros because the file is never opened by the application, and this should also make the search very fast.

Damon
Damon Ostrander is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT +1. The time now is 10:06 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.