Trying to write a script that
- If excel session already open, join it to this one,
- Excel session not open, thus create one.
First option works splendid! Second option doesn't work and does not give any explanation, just quits and does nothing!
Dim objXLApp, objXLWb, objXLWs
Dim XLWasRunning
XLWasRunning = True
Set objXLApp = GetObject(, "Excel.Application")
If Not TypeName(objXLApp) = "Empty" Then
strMessage = "Excel Running."
Else
strMessage = "Excel Not Running."
Set objXLApp = CreateObject("Excel.Application")
End If
Set objXLWb = objXLApp.Workbooks.Open("F:\GFD\Sam\Test\test.xlsx")
Set objXLWs = objXLWb.Sheets(1)
EDIT : changed CreateObject(, "Excel.Application") to CreateObject("Excel.Application")
CreateObject(, "Excel.Application")->CreateObject("Excel.Application")ELSEI don't even get a message box.objXLApp.Visible = True.objXLApp.Visible = Trueand it still doesn't work. Also when I run it with excel open, the cmd prompt stays open screen 4-5 seconds. When I don't have excel open, its on screen for a bout a tenth of a second?