But.. and there is always a but.....
I'm trying to allow the operator to select an excel file to read initially and then have it go unattended. I need to be able to read the sheet names from the file that is selected, which I'm having difficulty with. Marcus posted a very helpful, almost gets me there, solution a while back, which gets the sheet names for an open book. That works well. I've tried to extend this to passing it a variable for a file name, what I've learned is I don't know visual basic very well
I'm hoping someone can point me to where I'm going wrong. Here is the non-functioning code:
Code: Select all
VBSTART
Dim xlApp
Dim xlBook
Sub GetXL(xl)
Dim xlFileb
Set xlApp = GetObject(,"Excel.Application")
Set xlBook = xlApp.Workbooks.Open(xl, 0, True)
End Sub
Function SheetNames
Dim sList
sList = ""
For i = 1 To xlBook.Sheets.Count
sList = sList & xlBook.Sheets(i).Name & vbCRLF
Next
SheetNames = sList
End Function
VBEND
//VBRun>GetXL
Let>xlFile=C:\myspreadsheet.xlsx
XLOpen>%xlFile%,0,xlBook
VBRun>GetXL(xlFile)
VBEval>SheetNames,sSheetList
MessageModal>sSheetList
XLQuit>xlBook
Code: Select all
VBSTART
Dim xlApp
Dim xlBook
Sub GetXL
Dim xlFileb
Set xlApp = GetObject(,"Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\myspreadsheet.xlsx", 0, True)
End Sub
Function SheetNames
Dim sList
sList = ""
For i = 1 To xlBook.Sheets.Count
sList = sList & xlBook.Sheets(i).Name & vbCRLF
Next
SheetNames = sList
End Function
VBEND
//VBRun>GetXL
Let>xlFile=C:\myspreadsheet.xlsx
//XLOpen>%xlFile%,0,xlBook
XLOpen>%xlFile%,0,xlBook
VBRun>GetXL
VBEval>SheetNames,sSheetList
MessageModal>sSheetList
XLQuit>xlBook
My goal here is to not have Excel open visibly. Not super critical, but I would prefer it to not open. This seems to work since I run XLOpen with it not visible, because, I think, the GetXL routine uses the open book in excel. Problem is, I want to make sure I control which book I get the sheets from, which specifying the path seems to do.
Dan
[/code]