+ Reply to Thread
Results 1 to 5 of 5

declaring public variable value

  1. #1
    Damon
    Guest

    declaring public variable value

    Hi all,

    I have a public variable that is currently declared as string at the top
    module 1

    How and where should I set/define the variable value so that it is the same
    and available to any macro/procedure in the project/wookbook?

    currently trying

    set Pwd = "owntext" ' Pwd is the public variable

    The value for Pwd is the password for locking/unlocking sheets so I do not
    want to have to set it more than once if possible..

    On a kind of related note is there a way to stop people viewing the macros?

    I can protect pages, I can prevent the original file being over written, I
    can even prevent anybody other than me from saving the file at all but this
    is almost pointless if the user can view & edit macros

  2. #2
    Norman Jones
    Guest

    Re: declaring public variable value

    Hi Damon,

    Try:

    In a standard module try:


    Public PWORD As String


    Sub SetIt()
    PWORD = "MyPassword"
    End Sub

    Sub ReadIt()
    MsgBox PWORD
    End Sub

    ---
    Regards,
    Norman



    "Damon" <[email protected]> wrote in message
    news:[email protected]...
    > Hi all,
    >
    > I have a public variable that is currently declared as string at the top
    > module 1
    >
    > How and where should I set/define the variable value so that it is the
    > same
    > and available to any macro/procedure in the project/wookbook?
    >
    > currently trying
    >
    > set Pwd = "owntext" ' Pwd is the public variable
    >
    > The value for Pwd is the password for locking/unlocking sheets so I do not
    > want to have to set it more than once if possible..
    >
    > On a kind of related note is there a way to stop people viewing the
    > macros?
    >
    > I can protect pages, I can prevent the original file being over written, I
    > can even prevent anybody other than me from saving the file at all but
    > this
    > is almost pointless if the user can view & edit macros




  3. #3
    Norman Jones
    Guest

    Re: declaring public variable value


    Hi Damon,

    Forgot to respond to the second question:

    > On a kind of related note is there a way to stop people viewing the
    > macros?


    You can declare the sub as Private.

    You can put Option Private Module at the top of the module.

    You could add a dummy parameter to the sub.

    ---
    Regards,
    Norman



    "Damon" <[email protected]> wrote in message
    news:[email protected]...
    > Hi all,
    >
    > I have a public variable that is currently declared as string at the top
    > module 1
    >
    > How and where should I set/define the variable value so that it is the
    > same
    > and available to any macro/procedure in the project/wookbook?
    >
    > currently trying
    >
    > set Pwd = "owntext" ' Pwd is the public variable
    >
    > The value for Pwd is the password for locking/unlocking sheets so I do not
    > want to have to set it more than once if possible..
    >
    > On a kind of related note is there a way to stop people viewing the
    > macros?
    >
    > I can protect pages, I can prevent the original file being over written, I
    > can even prevent anybody other than me from saving the file at all but
    > this
    > is almost pointless if the user can view & edit macros




  4. #4
    Bob Phillips
    Guest

    Re: declaring public variable value

    Firstly, you can seta public variable anywhere. As public, it is accessible
    to any macro.

    Second, you do not Set a string variable, just assign it

    Pwd = "owntext"

    You can protect a project in the VBE, Tools>Properties>Protection, but it
    will only deter a casual onlooker, it is easily circumvented.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Damon" <[email protected]> wrote in message
    news:[email protected]...
    > Hi all,
    >
    > I have a public variable that is currently declared as string at the top
    > module 1
    >
    > How and where should I set/define the variable value so that it is the

    same
    > and available to any macro/procedure in the project/wookbook?
    >
    > currently trying
    >
    > set Pwd = "owntext" ' Pwd is the public variable
    >
    > The value for Pwd is the password for locking/unlocking sheets so I do not
    > want to have to set it more than once if possible..
    >
    > On a kind of related note is there a way to stop people viewing the

    macros?
    >
    > I can protect pages, I can prevent the original file being over written, I
    > can even prevent anybody other than me from saving the file at all but

    this
    > is almost pointless if the user can view & edit macros




  5. #5
    Norman Jones
    Guest

    Re: declaring public variable value

    Hi Damon.

    Apologies, I misread your second question. My suggestions prevent the macros
    in question from appearing in Excel's macro list.

    The broader question of hiding code has been addressed by Bob in his more
    apposite response.


    ---
    Regards,
    Norman



    "Norman Jones" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi Damon,
    >
    > Forgot to respond to the second question:
    >
    >> On a kind of related note is there a way to stop people viewing the
    >> macros?

    >
    > You can declare the sub as Private.
    >
    > You can put Option Private Module at the top of the module.
    >
    > You could add a dummy parameter to the sub.
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Damon" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hi all,
    >>
    >> I have a public variable that is currently declared as string at the top
    >> module 1
    >>
    >> How and where should I set/define the variable value so that it is the
    >> same
    >> and available to any macro/procedure in the project/wookbook?
    >>
    >> currently trying
    >>
    >> set Pwd = "owntext" ' Pwd is the public variable
    >>
    >> The value for Pwd is the password for locking/unlocking sheets so I do
    >> not
    >> want to have to set it more than once if possible..
    >>
    >> On a kind of related note is there a way to stop people viewing the
    >> macros?
    >>
    >> I can protect pages, I can prevent the original file being over written,
    >> I
    >> can even prevent anybody other than me from saving the file at all but
    >> this
    >> is almost pointless if the user can view & edit macros

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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