Killing Excel after Creating a Workbook in VB
Killing Excel after Creating a Workbook in VB
(OP)
Hi,
I'm writing in VB6. In my program, I create a workbook, add data to it, and format it. When all of that is done, I save the work book as some file name, and ATTEMPT to kill my Excel.application.
Here's the problem: I cannot fully open my newly created workbook if my program (the one that created it) is running. Excel starts up, and shows me the top menu bar, but doesn't 'fill-in' the rest of the screen. If I choose View|Full Screen, I can view my workbook!
DOES ANYONE KNOW WHAT I'M DOING WRONG? I assume I'm not completely killing off my Excel link to the workbook.
To see what I mean, you can
1. Open an new VB project (standard .exe)
2. Set a reference to 'Microsoft Excel 9.0 (or whatever) object Library'
3. Paste the following code into the Form_Load event:
'get a new excel app
Dim xlApp As New excel.Application
'open a workbook
xlApp.Workbooks.Add
'format a little
Range("A1:F1").Select
Selection.Interior.ColorIndex = 37
'save formatted worksheet
xlApp.ActiveWorkbook.SaveAs _
fileName:="C:\myWorkbook.xls", _
FileFormat:=xlWorkbookNormal
xlApp.Workbooks.Close
xlApp.Quit
4. Run the program and try to open the workbooke while the VB program is still running.
I REALLY appreciate any insight.
I'm writing in VB6. In my program, I create a workbook, add data to it, and format it. When all of that is done, I save the work book as some file name, and ATTEMPT to kill my Excel.application.
Here's the problem: I cannot fully open my newly created workbook if my program (the one that created it) is running. Excel starts up, and shows me the top menu bar, but doesn't 'fill-in' the rest of the screen. If I choose View|Full Screen, I can view my workbook!
DOES ANYONE KNOW WHAT I'M DOING WRONG? I assume I'm not completely killing off my Excel link to the workbook.
To see what I mean, you can
1. Open an new VB project (standard .exe)
2. Set a reference to 'Microsoft Excel 9.0 (or whatever) object Library'
3. Paste the following code into the Form_Load event:
'get a new excel app
Dim xlApp As New excel.Application
'open a workbook
xlApp.Workbooks.Add
'format a little
Range("A1:F1").Select
Selection.Interior.ColorIndex = 37
'save formatted worksheet
xlApp.ActiveWorkbook.SaveAs _
fileName:="C:\myWorkbook.xls", _
FileFormat:=xlWorkbookNormal
xlApp.Workbooks.Close
xlApp.Quit
4. Run the program and try to open the workbooke while the VB program is still running.
I REALLY appreciate any insight.





RE: Killing Excel after Creating a Workbook in VB
Option Explicit
Private Sub Command1_Click()
Dim xlApp As New Excel.Application
Dim xlWb As Workbook
Dim xlSht As Worksheet
'start a new excel app
Set xlApp = New Excel.Application
'open a workbook
Set xlWb = xlApp.Workbooks.Add
Set xlSht = xlWb.Sheets("Sheet1")
'format a little
xlSht.Range("A1:F1").Interior.ColorIndex = 37
'save formatted worksheet
xlWb.SaveAs _
FileName:="C:\myWorkbook.xls", _
FileFormat:=xlWorkbookNormal
xlWb.Close
xlApp.Quit
Set xlSht = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
MsgBox "Done"
Unload Me
End Sub
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Killing Excel after Creating a Workbook in VB
xlSht.Range("A1:J1").Select
With Selection
.HorizontalAlignment = xlLeft
.MergeCells = True
.Font.Size = 20
.Font.Bold = True
End With
to
With xlSht.Range("A1:J1")
.HorizontalAlignment = xlLeft
.MergeCells = True
.Font.Size = 20
.Font.Bold = True
End With
And it worked! Any insight into this?
- Thanks For the Help.
RE: Killing Excel after Creating a Workbook in VB
Glad to help.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.