Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default global 'path' declaration

Hi all

i need to have a global 'path' that all of my functions and subs have access
to, so that if i want to change the path, i need to change it only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default global 'path' declaration

Don't declare it in ThisWorkbook. Declare the constant in a
regular code module. If you do declare it in ThisWorkbook, you
need to reference the variable as ThisWorkbook.docPath.




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


"Gixxer_J_97" wrote in
message
...
Hi all

i need to have a global 'path' that all of my functions and
subs have access
to, so that if i want to change the path, i need to change it
only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run
any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it
public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default global 'path' declaration

thanks Chip!

just for clarification - can the const be defined in any code module, or
does it need to be defined in the module that it will be used? is there a
way to make it "global" or does defining it as const take care of that?


"Chip Pearson" wrote:

Don't declare it in ThisWorkbook. Declare the constant in a
regular code module. If you do declare it in ThisWorkbook, you
need to reference the variable as ThisWorkbook.docPath.




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


"Gixxer_J_97" wrote in
message
...
Hi all

i need to have a global 'path' that all of my functions and
subs have access
to, so that if i want to change the path, i need to change it
only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run
any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it
public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default global 'path' declaration

Declare it in a general module if you want easily see it in all parts of
your project

Public Const DocPath As String = "C:\Temp\"

Modules that are not general modules don't permit PUBLIC constants so
constants declared there are local/private to that module/class.

--
Regards,
Tom Ogilvy





"Gixxer_J_97" wrote in message
...
Hi all

i need to have a global 'path' that all of my functions and subs have

access
to, so that if i want to change the path, i need to change it only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default global 'path' declaration

If you declare it as Public, it can be in any code module, and
will be accessible to all code modules. If you omit the Public
declaration, the constant will be accessible only to the module
in which it is declared.


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


"Gixxer_J_97" wrote in
message
...
thanks Chip!

just for clarification - can the const be defined in any code
module, or
does it need to be defined in the module that it will be used?
is there a
way to make it "global" or does defining it as const take care
of that?


"Chip Pearson" wrote:

Don't declare it in ThisWorkbook. Declare the constant in a
regular code module. If you do declare it in ThisWorkbook, you
need to reference the variable as ThisWorkbook.docPath.




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


"Gixxer_J_97" wrote in
message
...
Hi all

i need to have a global 'path' that all of my functions and
subs have access
to, so that if i want to change the path, i need to change
it
only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and
run
any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it
public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other
functions?

any suggestions greatly appreciated!

thanks!

J








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default global 'path' declaration

If docpath is declared as a constant in ThisWorkbook, you can't declare it
as public and thus I don't believe you can use ThisWorkbook.docPath to refer
to it. At least it doesn't work in xl2003 in my tests.

--
Regards,
Tom Ogilvy

"Chip Pearson" wrote in message
...
Don't declare it in ThisWorkbook. Declare the constant in a
regular code module. If you do declare it in ThisWorkbook, you
need to reference the variable as ThisWorkbook.docPath.




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


"Gixxer_J_97" wrote in
message
...
Hi all

i need to have a global 'path' that all of my functions and
subs have access
to, so that if i want to change the path, i need to change it
only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run
any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it
public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default global 'path' declaration

If it is defined in any module other than the one it is to be used, use

Public Const DocPath As String= "C:\Temp\"

--

HTH

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


"Gixxer_J_97" wrote in message
...
thanks Chip!

just for clarification - can the const be defined in any code module, or
does it need to be defined in the module that it will be used? is there a
way to make it "global" or does defining it as const take care of that?


"Chip Pearson" wrote:

Don't declare it in ThisWorkbook. Declare the constant in a
regular code module. If you do declare it in ThisWorkbook, you
need to reference the variable as ThisWorkbook.docPath.




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


"Gixxer_J_97" wrote in
message
...
Hi all

i need to have a global 'path' that all of my functions and
subs have access
to, so that if i want to change the path, i need to change it
only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run
any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it
public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default global 'path' declaration

Yeah, you're right. I botched the answer.


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


"Tom Ogilvy" wrote in message
...
If docpath is declared as a constant in ThisWorkbook, you can't
declare it
as public and thus I don't believe you can use
ThisWorkbook.docPath to refer
to it. At least it doesn't work in xl2003 in my tests.

--
Regards,
Tom Ogilvy

"Chip Pearson" wrote in message
...
Don't declare it in ThisWorkbook. Declare the constant in a
regular code module. If you do declare it in ThisWorkbook, you
need to reference the variable as ThisWorkbook.docPath.




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


"Gixxer_J_97" wrote in
message
...
Hi all

i need to have a global 'path' that all of my functions and
subs have access
to, so that if i want to change the path, i need to change
it
only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and
run
any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it
public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other
functions?

any suggestions greatly appreciated!

thanks!

J







  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default global 'path' declaration

thats what i was looking for! thanks Tom!

J

"Tom Ogilvy" wrote:

Declare it in a general module if you want easily see it in all parts of
your project

Public Const DocPath As String = "C:\Temp\"

Modules that are not general modules don't permit PUBLIC constants so
constants declared there are local/private to that module/class.

--
Regards,
Tom Ogilvy





"Gixxer_J_97" wrote in message
...
Hi all

i need to have a global 'path' that all of my functions and subs have

access
to, so that if i want to change the path, i need to change it only in one
place

i have

const docPath="C:\Temp\"

defined in ThisWorkbook, but when i open the workbook and run any of my
functions trying to reference docPath, it is empty

is defining it as a const in ThisWorkbook not setting it public?
or do i need to do

public docPath

Private Sub Workbook_Open()
docPath = "C:\Temp\"
End Sub

?

doesn't that allow the path to be changed from other functions?

any suggestions greatly appreciated!

thanks!

J




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
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
which declaration to use Peer Excel Programming 3 August 2nd 04 03:17 PM
Global variable declaration! aiyer[_12_] Excel Programming 3 April 13th 04 04:35 PM
Declaration? TJF[_2_] Excel Programming 5 December 18th 03 03:26 PM
How to set global constants and get path of spreadsh ? wellie Excel Programming 1 July 11th 03 03:06 AM


All times are GMT +1. The time now is 09:14 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"