code to open second session of excel

Ima_learnin'

Active Member
Joined
Dec 14, 2002
Messages
266
Hello All,
Is there code that could open a second session of excel if I’m already in one session? I also need to understand how to open excel from VB6.0 but don’t know how to do it.

Thanks, Ima learnin’
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Okay, I believe that the first code will work in VB. Has not been tested, but I think the theory is right. Secondly, the last code will work in VBA but has some issues (at least on my PC). The new instance will close whenever the workbook that is created closes, and also will not clean itself up from memory. Just check and see if this happens to you also.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> OpenExcel_VBCode()
    <SPAN style="color:#00007F">Dim</SPAN> xlApp <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> xlWorkbook <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>

    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> xlApp = CreateObject("Excel.Application")
    <SPAN style="color:#00007F">If</SPAN> xlApp <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN>
        MsgBox "Unable to start Excel."
        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0

    <SPAN style="color:#00007F">Set</SPAN> xlWorkbook = xlApp.Workbooks.Add

    <SPAN style="color:#00007F">With</SPAN> xlWorkbook.Sheets(1)
        .Name = "New XL"
        .Range("A1") = "This is a new instance of XL."
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

    xlApp.Visible = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">'If you do not want it to show then remove this line</SPAN>

<SPAN style="color:#007F00">'    xlApp.Quit 'will close the newly created XL instance</SPAN>

    <SPAN style="color:#00007F">Set</SPAN> xlWorkbook = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> xlApp = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> OpenExcel_VBACode()
    <SPAN style="color:#00007F">Dim</SPAN> xlApp <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> Application
    <SPAN style="color:#00007F">Dim</SPAN> xlWorkbook <SPAN style="color:#00007F">As</SPAN> Workbook

    <SPAN style="color:#00007F">Set</SPAN> xlWorkbook = xlApp.Workbooks.Add

    <SPAN style="color:#00007F">With</SPAN> xlWorkbook.Sheets(1)
        .Name = "New XL"
        .Range("A1") = "This is a new instance of XL."
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

    xlApp.Visible = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">'If you do not want it to show then remove this line</SPAN>

<SPAN style="color:#007F00">'    xlApp.Quit 'will close the newly created XL instance</SPAN>

    <SPAN style="color:#00007F">Set</SPAN> xlWorkbook = <SPAN style="color:#00007F">Nothing</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> xlApp = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top