Opening an Excel spreadsheet by using a "Public Function"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can anybody help???
I an trying to create a Public Function for opening and closing a Excel Spreadsheet so that I can read data contained in the spreadsheet.
My program uses the following to open a Excel Spreadsheet
Public Function CentreDrillData()
Dim oXl As Object
Dim oXlWorkBook As Object
Dim oXLWorkSheet As Object
Set oXl = CreateObject("Excel.Application")
Set oXlWorkBook = oXl.Workbooks.Open(ToolDataFileName)
Set oXLWorkSheet = oXlWorkBook.Sheets(2)
For Counter = 3 To 13
If CentreDrillSize = Trim(oXLWorkSheet.cells(Counter, ToolDescriptionCell).Text) Then
SpindleSpeed = oXLWorkSheet.cells(Counter, PartMaterialCell + 1).Text
Depth = oXLWorkSheet.cells(Counter, ToolDescriptionCell + 1).Text
Exit For
End If
Next
Call CloseExcel(oXlWorkBook, oXl)
End Function
The CloseExcel works OK
I want to put the first 6 lines into a Public function thus....
Public Function OpenExcel(l)
Dim oXl As Object
Dim oXlWorkBook As Object
Dim oXLWorkSheet As Object
Set oXl = CreateObject("Excel.Application")
Set oXlWorkBook = oXl.Workbooks.Open(ToolDataFileName)
Set oXLWorkSheet = oXlWorkBook.Sheets(ExcelSheetNumber)
End Function
But this Public Function does not work!
I want to replace the first lines of the main function to Call OpenExcel.
Does anybody know what is wrong????
Many thanks in advance!!!
IsoCAM