Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default public const availability?


Using Excel VBA can a constant be available to multiple projects?


--
lcoreyl
------------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...fo&userid=2042
View this thread: http://www.excelforum.com/showthread...hreadid=552950

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default public const availability?

Not usually. You would need to set a reference from the workbooks that want
to use the constant to the workbook that defines the constant. Probably not
something you want to do.

A possible workaround could be:
In the workbook that contains the constant, you could put a sub that returns
its value

In a general module a workbook named ABC.xls as an example.

Public Const MyVal as Long = 10

Pubic Function ReturnMyVal()
ReturnMyVal = MyVal
End Function

then in the other workbook

v = Application.Run( "ABC.xl1!ABC")
msgbox v

now v will hold the value of the constant.
--
Regards,
Tom Ogilvy



"lcoreyl" wrote in
message ...

Using Excel VBA can a constant be available to multiple projects?


--
lcoreyl
------------------------------------------------------------------------
lcoreyl's Profile:

http://www.excelforum.com/member.php...fo&userid=2042
View this thread: http://www.excelforum.com/showthread...hreadid=552950



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default public const availability?


keep getting "macro not found"

tried creating (in the book with the constant) a macro named ABC wit
just the function in it, and still get the same error..

--
lcorey
-----------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=55295

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default public const availability?

There was a typo on the Application.Run string and in the spelling of Public
for the function - but fixing those I recreated the situation

In the workbook named ABC.xls, in Module1

Public Const MyVal As Long = 10

Public Function ReturnMyVal()
ReturnMyVal = MyVal
End Function

in another workbook

Sub GettheValue()
v = Application.Run("ABC.xls!ReturnMyVal")
MsgBox v
End Sub

the message box displayed 10

--
Regards,
Tom Ogilvy


"lcoreyl" wrote in
message ...

keep getting "macro not found"

tried creating (in the book with the constant) a macro named ABC with
just the function in it, and still get the same error...


--
lcoreyl
------------------------------------------------------------------------
lcoreyl's Profile:

http://www.excelforum.com/member.php...fo&userid=2042
View this thread: http://www.excelforum.com/showthread...hreadid=552950



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default public const availability?


I copied those directly into two workbooks and it still doesn't work.
It does open ABC.xls, but then says "The macro 'ABC.xls!ReturnMyVal
can not be found"

--
lcorey
-----------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=55295



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default public const availability?


Now it is working. I thought I needed the path of the ABC in th
application run command, and eveidently that messes it up, although i
does open ABC, but then not the macro. I just copied exactly what yo
had and now it works..

--
lcorey
-----------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=55295

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
Conditional format to highlight only cells with formula, not const hkbarnett Excel Worksheet Functions 2 November 19th 09 01:49 AM
relative path for const in vba code [email protected] Excel Programming 5 March 1st 06 04:29 PM
Not recognizing a Const Dan T[_3_] Excel Programming 7 July 18th 04 12:45 AM
Public Const on a Drive MD Excel Programming 1 July 15th 04 03:53 PM
crash changing const to public const BrianB Excel Programming 0 August 4th 03 10:13 AM


All times are GMT +1. The time now is 11:54 PM.

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

About Us

"It's about Microsoft Excel"