Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Evaluate a Name in Non-active WB

Maybe this

Sub EvalNameTest()
Dim v

With Workbooks("Book2")
.Names.Add "abc", "=124"
v = Application.Evaluate(.Names("abc").RefersTo)
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If


MsgBox v, , ActiveWorkbook.Name
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Peter T" <peter_t@discussions wrote in message
...
Anyone know the syntax to evaluate a Name in a Workbook that's not the
activeworkbook.

For example, in the following how to return v = 123 if ThisWorkbook is NOT
the active workbook (without using cells).

Sub EvalNameTest()
Dim v

With ThisWorkbook.Names
.Add "abc", "=123"
v = [abc]
.Item("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If

MsgBox v, , ActiveWorkbook.Name
End Sub


TIA, Peter T




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Evaluate a Name in Non-active WB

Hi Bob,

Yes that does work, but unfortunately it seems my example is not adequate.
Would you care to have a go with this:

Sub EvalNameTest2()
Dim s As String
Dim v

s = ThisWorkbook.Name ' try as active & non-active

With Workbooks(s)
.Names.Add "abc", "=Documents(1)"
'v = Application.Evaluate(.Names("abc").RefersTo) 'error 2015
v = [abc]
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
ElseIf IsArray(v) Then
v = v(LBound(v)) ' first workbook
End If

MsgBox v, , ActiveWorkbook.Name
End Sub

Regards,
Peter T

"Bob Phillips" wrote in message
...
Maybe this

Sub EvalNameTest()
Dim v

With Workbooks("Book2")
.Names.Add "abc", "=124"
v = Application.Evaluate(.Names("abc").RefersTo)
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If


MsgBox v, , ActiveWorkbook.Name
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my

addy)



"Peter T" <peter_t@discussions wrote in message
...
Anyone know the syntax to evaluate a Name in a Workbook that's not the
activeworkbook.

For example, in the following how to return v = 123 if ThisWorkbook is

NOT
the active workbook (without using cells).

Sub EvalNameTest()
Dim v

With ThisWorkbook.Names
.Add "abc", "=123"
v = [abc]
.Item("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If

MsgBox v, , ActiveWorkbook.Name
End Sub


TIA, Peter T






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Evaluate a Name in Non-active WB

Documents() is one of those long lost XLM functions that only exists in
names. So I thought ExecuteExcel4Macro might work, but we have to strip off
the = sign.

Application.ExecuteExcel4Macro(Mid(Workbooks("Book 1").Names("abc").RefersTo,
2))

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Peter T" <peter_t@discussions wrote in message
...
Hi Bob,

Yes that does work, but unfortunately it seems my example is not adequate.
Would you care to have a go with this:

Sub EvalNameTest2()
Dim s As String
Dim v

s = ThisWorkbook.Name ' try as active & non-active

With Workbooks(s)
.Names.Add "abc", "=Documents(1)"
'v = Application.Evaluate(.Names("abc").RefersTo) 'error 2015
v = [abc]
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
ElseIf IsArray(v) Then
v = v(LBound(v)) ' first workbook
End If

MsgBox v, , ActiveWorkbook.Name
End Sub

Regards,
Peter T

"Bob Phillips" wrote in message
...
Maybe this

Sub EvalNameTest()
Dim v

With Workbooks("Book2")
.Names.Add "abc", "=124"
v = Application.Evaluate(.Names("abc").RefersTo)
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If


MsgBox v, , ActiveWorkbook.Name
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my

addy)



"Peter T" <peter_t@discussions wrote in message
...
Anyone know the syntax to evaluate a Name in a Workbook that's not the
activeworkbook.

For example, in the following how to return v = 123 if ThisWorkbook is

NOT
the active workbook (without using cells).

Sub EvalNameTest()
Dim v

With ThisWorkbook.Names
.Add "abc", "=123"
v = [abc]
.Item("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If

MsgBox v, , ActiveWorkbook.Name
End Sub


TIA, Peter T








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Evaluate a Name in Non-active WB

Thanks for that but unfortunately where an XLM is expected to return an
array ExecuteExcel4Macro only returns the first element.

Regards,
Peter T

"Jon Peltier" wrote in message
...
Documents() is one of those long lost XLM functions that only exists in
names. So I thought ExecuteExcel4Macro might work, but we have to strip

off
the = sign.


Application.ExecuteExcel4Macro(Mid(Workbooks("Book 1").Names("abc").RefersTo,
2))

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Peter T" <peter_t@discussions wrote in message
...
Hi Bob,

Yes that does work, but unfortunately it seems my example is not

adequate.
Would you care to have a go with this:

Sub EvalNameTest2()
Dim s As String
Dim v

s = ThisWorkbook.Name ' try as active & non-active

With Workbooks(s)
.Names.Add "abc", "=Documents(1)"
'v = Application.Evaluate(.Names("abc").RefersTo) 'error 2015
v = [abc]
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
ElseIf IsArray(v) Then
v = v(LBound(v)) ' first workbook
End If

MsgBox v, , ActiveWorkbook.Name
End Sub

Regards,
Peter T

"Bob Phillips" wrote in message
...
Maybe this

Sub EvalNameTest()
Dim v

With Workbooks("Book2")
.Names.Add "abc", "=124"
v = Application.Evaluate(.Names("abc").RefersTo)
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If


MsgBox v, , ActiveWorkbook.Name
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my

addy)



"Peter T" <peter_t@discussions wrote in message
...
Anyone know the syntax to evaluate a Name in a Workbook that's not

the
activeworkbook.

For example, in the following how to return v = 123 if ThisWorkbook

is
NOT
the active workbook (without using cells).

Sub EvalNameTest()
Dim v

With ThisWorkbook.Names
.Add "abc", "=123"
v = [abc]
.Item("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If

MsgBox v, , ActiveWorkbook.Name
End Sub


TIA, Peter T










  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Evaluate a Name in Non-active WB

Yeah, I got hung up on that one. I could easily get the array in the
worksheet, but not via VBA.

How about temporarily dumping it into a worksheet (using .FormulaArray), and
using a variant array to get that into VBA?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Peter T" <peter_t@discussions wrote in message
...
Thanks for that but unfortunately where an XLM is expected to return an
array ExecuteExcel4Macro only returns the first element.

Regards,
Peter T

"Jon Peltier" wrote in message
...
Documents() is one of those long lost XLM functions that only exists in
names. So I thought ExecuteExcel4Macro might work, but we have to strip

off
the = sign.


Application.ExecuteExcel4Macro(Mid(Workbooks("Book 1").Names("abc").RefersTo,
2))

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Peter T" <peter_t@discussions wrote in message
...
Hi Bob,

Yes that does work, but unfortunately it seems my example is not

adequate.
Would you care to have a go with this:

Sub EvalNameTest2()
Dim s As String
Dim v

s = ThisWorkbook.Name ' try as active & non-active

With Workbooks(s)
.Names.Add "abc", "=Documents(1)"
'v = Application.Evaluate(.Names("abc").RefersTo) 'error 2015
v = [abc]
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
ElseIf IsArray(v) Then
v = v(LBound(v)) ' first workbook
End If

MsgBox v, , ActiveWorkbook.Name
End Sub

Regards,
Peter T

"Bob Phillips" wrote in message
...
Maybe this

Sub EvalNameTest()
Dim v

With Workbooks("Book2")
.Names.Add "abc", "=124"
v = Application.Evaluate(.Names("abc").RefersTo)
.Names("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If


MsgBox v, , ActiveWorkbook.Name
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Peter T" <peter_t@discussions wrote in message
...
Anyone know the syntax to evaluate a Name in a Workbook that's not

the
activeworkbook.

For example, in the following how to return v = 123 if ThisWorkbook

is
NOT
the active workbook (without using cells).

Sub EvalNameTest()
Dim v

With ThisWorkbook.Names
.Add "abc", "=123"
v = [abc]
.Item("abc").Delete
End With

If IsError(v) Then
v = CStr(v)
End If

MsgBox v, , ActiveWorkbook.Name
End Sub


TIA, Peter T














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
Row select mode to highlight active row of active cell Bart Fay[_2_] Excel Discussion (Misc queries) 0 May 11th 10 09:34 PM
run macro although blinking cursor is active in an active cell bartman1980 Excel Programming 1 December 20th 07 11:29 AM
I need to sort an active sheet using the col of the active cell HamFlyer Excel Programming 3 June 6th 06 07:25 PM
How to write vba to evaluate the text font and size on an active cell range? Paul Excel Programming 2 February 20th 06 08:48 PM
HOW TO COPY 480 ACTIVE E-MAIL ADDRESSES CLM "G" ON AN ACTIVE EXCE. ragman10 Excel Discussion (Misc queries) 1 December 13th 04 11:52 PM


All times are GMT +1. The time now is 07:15 AM.

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"