Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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, ToolsPropertiesProtection, but it
will only deter a casual onlooker, it is easily circumvented.

--

HTH

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


"Damon" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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" wrote in message
...

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
declaring public variables Loane Sharp Excel Programming 2 March 18th 05 05:44 PM
Declaring a Public variable as a Range and its lifetime John Wirt[_5_] Excel Programming 8 January 23rd 05 06:40 AM
Declaring Variables Public ob3ron02[_9_] Excel Programming 1 October 25th 04 06:11 PM
Declaring Variables Public ob3ron02[_8_] Excel Programming 1 October 25th 04 02:14 PM
Declaring Public Procedure mac Excel Programming 3 December 3rd 03 05:01 PM


All times are GMT +1. The time now is 05:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"