As part of a bigger project, I have the following Sub that opens another workbook and passes certain parameters to it.
The Shell open an excel workbook has certain command line parameters (/e/r) that when passed to the file it runs a procedure using an ODBC connection.
This runs fine. However, then when I try to check if the workbook is open via:
the function return FALSE. My it is bacause it is another Excel session and it does not recognise it as the same application.
I need to read some values from that workbook. My question is, how do I interact with that workbook?
This, for example, does not work. (strStuff is the workbook opened using the shell command)
Workbooks(strBuff).Worksheets("Report").Range("A1").value
Any ideas on how to reach the newly opened workbook using this method. I cannot use workbooks.open xxxxx because I cannot pass command line parameters that way.
Any ideas? Thanks
The Shell open an excel workbook has certain command line parameters (/e/r) that when passed to the file it runs a procedure using an ODBC connection.
Code:
Sub OpenDataFile()
Dim RetVal As Variant
' Open Excel File capable of Reading routes Export DB to generate Report
With ThisWorkbook.Worksheets("Menu")
RetVal = Shell("excel.exe """ & .Range("DBFile").Value & """ " & .Range("CLine").Value & "", 1)
AppActivate RetVal
End With
End Sub
This runs fine. However, then when I try to check if the workbook is open via:
Code:
Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
WorkbookOpen = True
Exit Function
End If
WorkBookNotOpen:
End Function
the function return FALSE. My it is bacause it is another Excel session and it does not recognise it as the same application.
I need to read some values from that workbook. My question is, how do I interact with that workbook?
This, for example, does not work. (strStuff is the workbook opened using the shell command)
Workbooks(strBuff).Worksheets("Report").Range("A1").value
Any ideas on how to reach the newly opened workbook using this method. I cannot use workbooks.open xxxxx because I cannot pass command line parameters that way.
Any ideas? Thanks