Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How to access a function from a different workbook

Hi everyone.
I have 2 worksheets, say Workbook1 and Workbook2.
I have a routine in Workbook1 which needs to retrieve a value from Workbook2.
For example in Workbook1 I have:

Sub GetValueFromWorkbook2()
Dim val as Integer
val = Application.Run ("'Workbook2.xla'!GetValue")
MsgBox (val)
End Sub

and in Workbook2 which is also opened and acquired certain values before
call from Workbook1, I have:

Private val as Integer

Private Sub Workbook_Open()
val = 5
End Sub

Public Function GetValue()
GetValue = val
End

This would display 0, instead of 5. So, how will I get the correct value?

Thanks in advance. :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default How to access a function from a different workbook

I may be wrong, but I think that your GetValue function needs to be in a
module rather than in the thisworkbook space. In addition, as the function
is now not in thisworkbook, the declaration for val would need to be public
and not private.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"jean grey" wrote:

Hi everyone.
I have 2 worksheets, say Workbook1 and Workbook2.
I have a routine in Workbook1 which needs to retrieve a value from Workbook2.
For example in Workbook1 I have:

Sub GetValueFromWorkbook2()
Dim val as Integer
val = Application.Run ("'Workbook2.xla'!GetValue")
MsgBox (val)
End Sub

and in Workbook2 which is also opened and acquired certain values before
call from Workbook1, I have:

Private val as Integer

Private Sub Workbook_Open()
val = 5
End Sub

Public Function GetValue()
GetValue = val
End

This would display 0, instead of 5. So, how will I get the correct value?

Thanks in advance. :)

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
workbook to access jnewl Excel Programming 8 October 18th 08 06:44 AM
Access Data from Workbook without seeing the workbook open. RyanH Excel Programming 1 August 29th 08 04:23 PM
link Access workbook to Excel workbook Toinett Excel Discussion (Misc queries) 1 January 31st 05 03:37 PM
Function "User()" to provide access to workbook Wayne[_5_] Excel Programming 1 January 13th 04 02:06 AM
Can't access to a WorkBook Jordi Excel Programming 1 November 15th 03 06:24 AM


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