Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Reading a VBA constant value by an outsider macro?

Rob,

Yes, it is possible. In workbook A, declare the constant:

Public Const cPASSWORD = "chip"

Then, go to the Tools menu, choose Properties, and give the project a new
name like TestProject. Save the file.

In workbook B, in the VBA editor, go to the Tools menu, choose References,
and put a check next to A's project name, TestProject.

You can then use the constant declared in A with code in B like

MsgBox TestProject.cPASSWORD

You can prevent this cross-project referencing by placing 'Option Private
Module' at the top of the code module. When Option Private Module is in
effect, procedures, properties, variables, and constants can be used only
from within the same project. The aren't exposed to other projects.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



"Rob" wrote in message
m...
Hello FellowNewsgroupReaders,

I think I know quite a lot of protecting my projects and spreadheets.
I create a workbook called "A.XLS".
VBA code stores a password to open another sheet.
In VBA I declare a constant, like
const constPass = "123"
I protect the VBA code with a password.

If I open "A.xls" and create another sheet "B.xls", is it possible to
create code to read the constant from the VBA in "A.xls"?

I suspect it is NOT possible. I just want to know IF it possible in any

way.
If so, I cannot store my password in a constant and I need to find another
solution. But the solution above will help me make things easier.

Am I right with this?

Regards,
Rob Zoomer




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Reading a VBA constant value by an outsider macro?

Chip,
Thank you for this clear answer. I tested it and it works great. This way my
passwords are not 'in the air' and I can easily change them for they are all
together in one batch of declarations.

Regards,
Rob

"Chip Pearson" schreef in bericht
...
Rob,

Yes, it is possible. In workbook A, declare the constant:

Public Const cPASSWORD = "chip"

Then, go to the Tools menu, choose Properties, and give the project a new
name like TestProject. Save the file.

In workbook B, in the VBA editor, go to the Tools menu, choose References,
and put a check next to A's project name, TestProject.

You can then use the constant declared in A with code in B like

MsgBox TestProject.cPASSWORD

You can prevent this cross-project referencing by placing 'Option Private
Module' at the top of the code module. When Option Private Module is in
effect, procedures, properties, variables, and constants can be used only
from within the same project. The aren't exposed to other projects.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



"Rob" wrote in message
m...
Hello FellowNewsgroupReaders,

I think I know quite a lot of protecting my projects and spreadheets.
I create a workbook called "A.XLS".
VBA code stores a password to open another sheet.
In VBA I declare a constant, like
const constPass = "123"
I protect the VBA code with a password.

If I open "A.xls" and create another sheet "B.xls", is it possible to
create code to read the constant from the VBA in "A.xls"?

I suspect it is NOT possible. I just want to know IF it possible in any

way.
If so, I cannot store my password in a constant and I need to find

another
solution. But the solution above will help me make things easier.

Am I right with this?

Regards,
Rob Zoomer






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
VBA macro for reading text file into Excel Javed Khan Excel Discussion (Misc queries) 0 October 14th 09 06:29 PM
Reading File Name in VB Macro that contains today's date dhstein Excel Discussion (Misc queries) 10 November 13th 08 02:48 AM
Reading Word document by using Excel Macro Arvind Mane Excel Discussion (Misc queries) 2 September 26th 08 07:55 AM
Please Help for a macro reading files not in sequence Francesco Excel Discussion (Misc queries) 8 April 15th 06 06:13 PM
auto reading macro Rich Excel Discussion (Misc queries) 3 February 7th 06 03:36 AM


All times are GMT +1. The time now is 05:30 AM.

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"