read data excel spreadsheet
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft VBA Training and help » Read data from Excel spreadsheet

Read data from Excel spreadsheet

resolvedResolved · Low Priority · Version 2003

replyReply Fri 16 Jul 2010, 16:09Delegate Kenneth said...

Kenneth has attended:
Excel VBA Intro Intermediate course

Read data from Excel spreadsheet

How do we read data from an Excel spreadsheet without opening the workbook?

For upcoming training course dates see: Pricing & availability

replyReply Mon 19 Jul 2010, 07:22Trainer Anthony said...

RE: Read data from Excel spreadsheet

Hi Ken, thanks for posting your query. Open a new spreadsheet and write your name into cell A1. Then save that spreadsheet to c:\. Close it, and then open another new spreadsheet, Alt + F11 and create a new module with this code:

Sub ReadClosed()

Dim strPath As String
Dim strFile As String
Dim strInfoCell As String
Dim myvalue As String

strPath = "c:\"
strFile = "myspreadsheet.xls"
strInfoCell = "'" & strPath & "[" & strFile & "]Sheet1'!R1C1"

myvalue = ExecuteExcel4Macro(strInfoCell)
MsgBox myvalue
Sheets("Sheet1").Range("A1").Value = myvalue


End Sub

That should display a messagebox with the value from your closed spreadsheet and write it into cell A1 on your new sheet. I haven't tested this with vast quantities of data, but you should be able to cannibilise this code for what you want to do.

Hope this helps,

Anthony

Sun 25 Jul 2010: Automatically marked as resolved.

 

Please browse our web site to find out more about
microsoft access vba and other Microsoft training courses.

Vba tip:

Use GoTo to Select A Cell With VBA

To select a certain cell on a Worksheet you can use:

Application.Goto Reference:=Range("V300")

or more simply

Range("V300").Select

If, on the other hand, you want the selected cell to be the top/left cell on the screen you use:

Application.Goto Reference:=Range("V300"), Scroll=True

View all VBA hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard