+ Reply to Thread
Results 1 to 8 of 8

Document properties to store variable value for future use

Hybrid View

dorabajji Document properties to store... 08-25-2020, 03:03 PM
vba_php Re: Document properties to... 08-25-2020, 04:38 PM
dorabajji Re: Document properties to... 08-25-2020, 11:41 PM
vba_php Re: Document properties to... 08-25-2020, 11:56 PM
dorabajji Re: Document properties to... 08-26-2020, 12:04 AM
vba_php Re: Document properties to... 08-26-2020, 12:10 AM
romperstomper Re: Document properties to... 08-26-2020, 04:52 AM
protonLeah Re: Document properties to... 08-26-2020, 11:33 PM
  1. #1
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Document properties to store variable value for future use

    Hi,
    Is there anyway to store a variable value outside worksheet cells or as a text file, for future use , so that variable value can be retrieved.
    Like in google sheets- property service. Like that excel can be done?

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Document properties to store variable value for future use

    the property service that you speak of, offered by google, does not serve the purpose you are asking about. it is more like the concept of a cookie storing encrypted data when you log into a website. however, to your question.....YES you can store data virtually anywhere on an OS system using almost any method created over the last 30 years basically. but, in VBA, of course you can use a var. just throw the text into it, then throw it out wherever you want. however, a string variable, which is what you want to use here, DOES have limits. so obviously you can't store massive amounts of data in one variable. see here for the bounds of what VBA can do:

    VBA string data type limitations, microsoft documentation

  3. #3
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Re: Document properties to store variable value for future use

    Hi,
    I checked the link you had provided .
    But how to store and retrieve.
    Currently i use inputbox for getting value and storing in worksheet
    and then checking if it exist, if not again showing up input box.

    What happens , this file is getting circulated, hence the ranges are getting deleted, hence i want dont want to get the input box
    to enter, if the value is set by one user and others simply follow the file .

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Document properties to store variable value for future use

    well let us see now.....hence, hence, hence, hence....LOL. I don't think I understood anything you said except for the fact that you are using an input box to capture text. so, if I read your orig. post right, you are doing something like this:
    get:
    s = inputbox("enter the data")
       if s <> "" then
          'THROW THE DATA TO THE WORKSHEET
       else
          go to get
       end if
    now, to another relevant point that can provide some value to you in your little journey here....you really need to research the concept called scope. it is a very relevant concept in the world of programming, and it is very closely related to how variables are used in any given program. so, for instance in VBA there are a few different "scopes". they are called global, private and public. and what that means is that variables declared with these qualifying scopes can be ""seen"" by other parts of the program that are located in different architectural areas of the program's layout. you can use this to your advantage, I believe. because, I don't think, that say for instance, global vars or public vars lose their values when code routines behind excel's interface end and/or are terminated. I might be wrong though. it's been a LONG time since I've checked on that.

    and of course, storing info can be done countless other ways too. like storing it on a hidden sheet, throwing it to a text file with like, say, the PUT statement in a file I/O stream, etc...

    does any of this help??

  5. #5
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Re: Document properties to store variable value for future use

    no the file, is sent over mail. So if i store the value in text file or outside workbook , it would be a problem and the contents of the worksheet are cleared when new data comes from import macro. So that also cannot be done.

    My point is the user who first sets the value from input box ( like property service in google , where you can set and retrieve the value of variable)
    is stored somewhere in the file. Not hidden sheet or in the current worksheet.
    so when the file, circulates to other person, then they need not see the input box asking them to enter date again.

    at present , i do like this

    if range("A1")="" then
    inputbox()
    else
    a=range("A1").value


    the above, i store in a hidden sheet on A1 at present. But the macro deletes all the worksheet apart from main sheet, hence i want to use some alternative.

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Document properties to store variable value for future use

    well if you are circulating a single worksheet around to everyone without linking or using sharepoint or anything like that, then obviously the input box will happen everytime. if you don't want new people to see the input box again, just write an ''IF'' statement in the code and check if the date is stored wherever you put it. it literally should be THAT easy. if the date is being deleted with the macro you speak of, everytime you circulate it to a new person, then obviously you need to fix that. that doesn't make sense.

    if the deletion of data is the real problem, and you definitely need the input box to stay in the code and you never know if the date is going to be available to be checked everytime you do whatever, then put an ''IF'' statement in the code and run the box if the date is NOT found. again, it's literally that easy.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,131

    Re: Document properties to store variable value for future use

    You could use a function like this - just call it whenever you need the name value and it will either retrieve an existing name, or create a new one and assign the value using the Inputbox:

    Function GetNameValue(NameOfName As String, Optional wb As Workbook)
        If wb Is Nothing Then Set wb = ActiveWorkbook
        On Error Resume Next
        Dim nm As Name
        Set nm = wb.Names(NameOfName)
        On Error GoTo 0
        If nm Is Nothing Then
            Dim NameValue
            NameValue = InputBox("Enter value for name")
            wb.Names.Add Name:=NameOfName, RefersTo:=NameValue
        Else
            NameValue = wb.Worksheets(1).Evaluate(NameOfName)
        End If
            
        GetNameValue = NameValue
    End Function
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    13,028

    Re: Document properties to store variable value for future use

    You can also use one of the workbooks unused built-in document properties such as "content status" like:
    ThisWorkbook.BuiltinDocumentProperties("Content status") = myVar
    myvar = ThisWorkbook.BuiltinDocumentProperties("Content status")
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Where can I find the variable type of the optional Document Properties?
    By aquixano in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-17-2019, 12:15 PM
  2. Using Document Properties to store a variable during an Excel Session
    By aquixano in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2019, 06:52 AM
  3. Master document for future documents
    By Throughstream in forum Excel General
    Replies: 6
    Last Post: 08-13-2018, 03:08 AM
  4. [SOLVED] Find where users wants to save file, and store for future saves in cell.
    By C J W in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-21-2017, 02:49 AM
  5. [SOLVED] Is there any reason to not use defined names to store properties?
    By foxguy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-25-2012, 03:18 PM
  6. [SOLVED] Properties of a document, help!
    By Jason in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-24-2006, 06:50 AM
  7. [SOLVED] Document Properties
    By Barb R. in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-23-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1