-
October 15th, 2004, 04:23 AM
#1
Reading Excel sheet from a Folder
Hi,
I can read an Excel file from the following code,however I am not sure where i am going to provide the path of sheet located in a folder.
Can somebody help?I am new to VB.
Public OD As Double, OD1 As Double, BWG As Double, BWG1 As Double, Pr As Double, K1 As Double
Public irow As Integer, icol As Integer
Sub Corr_Factor()
Dim objXL As Excel.Application
Dim objSHEET As Excel.Worksheet
Dim objWBOOK As Excel.Workbook
Set objXL = ActiveWorkbook.Excel4IntlMacroSheets.Application
'--Point to Data Sheet--
Set objSHEET = objXL.Sheets("Corr Factor K1")
objXL.Sheets("Corr Factor K1").Select
OD = objXL.ActiveSheet.Cells(55, 2).Value
BWG = objXL.ActiveSheet.Cells(56, 2).Value
Pr = objXL.ActiveSheet.Cells(57, 2).Value
Thanks
-
October 15th, 2004, 04:38 AM
#2
Re: Reading Excel sheet from a Folder
Hi,
Dim mcApp As Excel.Application
Set mcApp = New Excel.Application
mcApp.Workbooks.Open "your file"
for opening a file.
if this is not what you are looking for please redefine your question.
with kind regards,
Jeffrey
A VB programmer trying to stay alive in a Real C World
If the hardware is so great.. why use software to correct it..?? It will only slow it down..
Al is de hardware nog zo snel de software achterhaalt het wel
-
October 15th, 2004, 05:09 AM
#3
Re: Reading Excel sheet from a Folder
Thanks Buddy.
If I understand it correctly
mcApp.Workbooks.Open "your file"
In place of your file in double quotes...I need to specify the path of my Excel sheet..like "C:\Hdagar\sheet1.xls"....
Please correct me if i am wrong.
Thanks
-
October 15th, 2004, 05:17 AM
#4
-
October 15th, 2004, 05:28 AM
#5
Re: Reading Excel sheet from a Folder
-
October 18th, 2004, 01:41 AM
#6
Re: Reading Excel sheet from a Folder
Hi Jewe,
I am facing this run time error '9' on the piece of code below:
Set objSHEET = objXL.Sheets("C:\Model.xls").
Code above this code is:
Private Sub CommandButton7_Click()
Dim OD As Double, OD1 As Double, BWG As Double, BWG1 As Double, Pr As Double, K1 As Double
Dim irow As Integer, icol As Integer
Dim objXL As Excel.Application
Dim objSHEET As Excel.Worksheet
Dim objWBOOK As Excel.Workbook
Set objXL = ActiveWorkbook.Excel4IntlMacroSheets.Application.
My requirement is to read the Excel file "Model" lying at C:\...drive.In Excel file I need to read the Worksheet named as "CYCLE REQUEST".
From Cycle reuqest sheet,I need to to get the values of a particular cell for which i am using following code:
OD = objXL.ActiveSheet.Cells(8, 2).Value.
Could you please share your thoughts on this.
-
October 18th, 2004, 02:27 AM
#7
Re: Reading Excel sheet from a Folder
Hi,
error 9 = Subscript out of range
looks like you did not actually load the excel file.
Code:
Dim cExcel As Excel.Application
Dim cSheet As Excel.Worksheet
Set cExcel = New Excel.Application
'see what we are doing
cExcel.Visible = True
'open the file
cExcel.Workbooks.Open "C:\Temp\a.xls"
'second sheet is called jewe in my case
Set cSheet = cExcel.Sheets("jewe")
'so that we can see some action
cSheet.Activate
'add some text
cSheet.Cells(1, 1) = "Jewe testing"
A VB programmer trying to stay alive in a Real C World
If the hardware is so great.. why use software to correct it..?? It will only slow it down..
Al is de hardware nog zo snel de software achterhaalt het wel
-
October 18th, 2004, 03:49 AM
#8
Re: Reading Excel sheet from a Folder
Thanks a lot.
Actually I got the problem after posting this and it is working fine.
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|