Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default is it possible to get an object without opening the book

hi,

is it possible to get an object without opening the book
i mean ,for instance how to get a cell value without opening the book in vba

thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default is it possible to get an object without opening the book

no


"EXCEL$B!!(BNEWS" wrote in message
...
hi,

is it possible to get an object without opening the book
i mean ,for instance how to get a cell value without opening the book in
vba

thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default is it possible to get an object without opening the book

Public Sub GetData()
Dim oRS As Object
Dim sFilename As String
Dim sConnect As String
Dim sSQL As String
Dim ary

sFilename = "c:\Mytest\Volker1.xls"
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFilename & ";" & _
"Extended Properties=Excel 8.0;"

sSQL = "SELECT * FROM [Sales$]"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, 0, 1, 1

If Not oRS.EOF Then
ary = oRS.getrows
MsgBox "Cell A2: " & ary(0, 0)
MsgBox "Cell D4: " & ary(3, 2)
Else
MsgBox "No records returned.", vbCritical
End If

oRS.Close
Set oRS = Nothing

End Sub




--

HTH

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


"EXCEL$B!!(BNEWS" wrote in message
...
hi,

is it possible to get an object without opening the book
i mean ,for instance how to get a cell value without opening the book in

vba

thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default is it possible to get an object without opening the book


Another method

Sub test()
MsgBox GetValue("C:\test", "A1.xls", "Sheet1", "A1")
End Sub

Function GetValue(path, file, sheet, range_ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function


--
http://www.vba.com.tw/plog/


"EXCEL NEWS" wrote:

hi,

is it possible to get an object without opening the book
i mean ,for instance how to get a cell value without opening the book in vba

thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default is it possible to get an object without opening the book

You and John Walkenbach must be of like mind:

http://www.j-walk.com/ss/excel/tips/tip82.htm
A VBA Function to Get a Value From a Closed File

Nonetheless, this would be a real slow way to get a single value.

Faster would be to build a link in the cell and retrieve the value returned.

Function GetValue(path, file, sheet, range_ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)
with Activesheet.Range("B9")
.Formula = "=" & arg
GetValue = .Value
.ClearContents
end With
End Function

--
Regards,
Tom Ogilvy

"chijanzen" wrote in message
...

Another method

Sub test()
MsgBox GetValue("C:\test", "A1.xls", "Sheet1", "A1")
End Sub

Function GetValue(path, file, sheet, range_ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function


--
http://www.vba.com.tw/plog/


"EXCEL?NEWS" wrote:

hi,

is it possible to get an object without opening the book
i mean ,for instance how to get a cell value without opening the book in

vba

thanks






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default is it possible to get an object without opening the book


Tom Ogilvy skrev:

You and John Walkenbach must be of like mind:

http://www.j-walk.com/ss/excel/tips/tip82.htm
A VBA Function to Get a Value From a Closed File


Heh, good observation :)

What WAS strange was the actual differences (or difference, mayhaps).

/impslayer, aka Birger Johansson, not contributing at all

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
Replace Book 1 When Opening File in Excel Lize Excel Discussion (Misc queries) 0 October 11th 07 12:42 PM
excel crash when opening work book squid509 Excel Discussion (Misc queries) 1 July 6th 07 02:41 PM
How do I stop Book 1 opening with existing files? sirbob Excel Discussion (Misc queries) 2 April 3rd 06 10:18 AM
Opening in a new book ceemo[_13_] Excel Programming 5 August 19th 05 03:04 PM
Book 1 auto opening Mark Goulty Excel Programming 2 June 16th 04 09:45 AM


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