Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Open an Excel object

Hi all,

Do you know why when I execute this only macro line :

set ExcelApp = createobject("Excel.Application")

Why an excel application open and close directly ? (I see it in task manager) ?

thanks

4 Replies
Not applicable
Author

Is that the end of your macro? When your macro ends, it could release the Excel app object.

You are able to open an Excel object and manipulate it via macro. Here's a sample:

Sub Excel_OLE_Automation
Set oXL=CreateObject("Excel.Application")
f_name=oXL.GetOpenFilename("All Files (*.*),*.*",,"Select file",False)
If f_name="False" then
'user cancelled out of dialog box
Set oXL=nothing
Exit sub
End If
ActiveDocument.Variables("vFileName").SetContent f_name, true
Set oWB=oXL.Workbooks.Open(f_name)
Set oSH=oWB.Worksheets.Item(1)
oSH.Range("A2") = "12345"
oWB.Save
oWB.Close
Set oSH=nothing
Set oWB=nothing
Set oXL=nothing
End Sub


Not applicable
Author

"When your macro ends, it could release the Excel app object."

Really Tongue Tied It's not so common !

Not applicable
Author

No, not really, I was able to open an Excel object and leave it open after the macro ended.

What are you trying to accomplish with your macro? I think you need to do a little more to fully open the Excel and keep it open. Are you trying to start Excel and create a new file? Do you just want to open Excel with no file?

Here is the minimum I was able to use to get Excel to open and stay open after the macro ended:

Sub SimpleAuto
Set oXL=CreateObject("Excel.Application")
oXL.Visible = True

f_name=oXL.GetOpenFilename("All Files (*.*),*.*",,"Select file",False)
If f_name="False" then 'user cancelled out of dialog box
Set oXL=nothing
Exit sub
End If

Set oWB=oXL.Workbooks.Open(f_name)
Set oSH=oWB.Worksheets.Item(1)
End Sub


Not applicable
Author

Finally, I have no problem!

Usually when I use a COM object for Excel (in a vbs or other), the Excel application remains active if I do not close it.

So when I check only the line CreateObject ("Excel.Application") and I see this Excel application creating and immediately quit ... I am surprised and check if there is not a bug on my computer! I can not imagine that the VB engine in QV would close it automatically!

So there is no problem (finally)