F
Fredrik Glockner
I have an application where I need to read data into a Visual Basic
program. The data is to be read from sheets with the same names, but
they reside in different directories according to parameters.
It would be best for me if I could read this data into Visual Basic
without opening the sheet where the data resides. This is because the
user might very well have a sheet open already with the same name.
I know that one can read data from a non-opened sheet with this kind of
method:
Sub ExcelMagic()
' Read from an Excel sheet without opening it first
sPath = "C:"
sBook = "Book1.xls"
sSheet = "Sheet1"
sCmd = "SUM('" & sPath & "\[" & sBook & "]" & sSheet & "'!R1C1:R10C10)"
nAns = Application.ExecuteExcel4Macro(sCmd)
MsgBox nAns
End Sub
The problem with this method is that it is only capable of reading one
single value off the sheet at a time. I would like to read a whole
matrix of values. Somewhat naïvely, I have tried to alter the code to
something like this:
sCmd = "'" & sPath & "\[" & sBook & "]" & sSheet & "'!R1C1:R10C10"
But it does not work.
Do anybody have an idea for how I could solve this problem?
Fredrik
program. The data is to be read from sheets with the same names, but
they reside in different directories according to parameters.
It would be best for me if I could read this data into Visual Basic
without opening the sheet where the data resides. This is because the
user might very well have a sheet open already with the same name.
I know that one can read data from a non-opened sheet with this kind of
method:
Sub ExcelMagic()
' Read from an Excel sheet without opening it first
sPath = "C:"
sBook = "Book1.xls"
sSheet = "Sheet1"
sCmd = "SUM('" & sPath & "\[" & sBook & "]" & sSheet & "'!R1C1:R10C10)"
nAns = Application.ExecuteExcel4Macro(sCmd)
MsgBox nAns
End Sub
The problem with this method is that it is only capable of reading one
single value off the sheet at a time. I would like to read a whole
matrix of values. Somewhat naïvely, I have tried to alter the code to
something like this:
sCmd = "'" & sPath & "\[" & sBook & "]" & sSheet & "'!R1C1:R10C10"
But it does not work.
Do anybody have an idea for how I could solve this problem?
Fredrik