K
Kraig Kuusinen
I am not able to delete worksheets after I am done with them. I copy lines
from "Sheet2" and "Sheet3" to "Sheet1" thoughout the code. I want to delete
them before saving the template to another Excel file for production.
Here is the declarations and code:
Dim objExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Dim xlSheet2 As Excel.Worksheet
Dim xlSheet3 As Excel.Worksheet
Set objExcel = New Excel.Application
Set xlBook = objExcel.Workbooks.Open(sTemplatePath & sTemplateName)
Set xlSheet1 = xlBook.Worksheets("Sheet1")
Set xlSheet2 = xlBook.Worksheets("Sheet2")
Set xlSheet3 = xlBook.Worksheets("Sheet3")
xlBook.Worksheets("Sheet2").Delete
xlBook.Worksheets("Sheet3").Delete
sInvName = sContractNum & " Centralized Bill " & sMonth & " " & sYear & "
Bill.xls"
xlBook.SaveAs (sCentralPath & sInvName)
Set xlSheet1 = Nothing
Set xlSheet2 = Nothing
Set xlSheet3 = Nothing
Set xlBook = Nothing
objExcel.Quit
Set objExcel = Nothing
Thanks for any help.
Kraig
from "Sheet2" and "Sheet3" to "Sheet1" thoughout the code. I want to delete
them before saving the template to another Excel file for production.
Here is the declarations and code:
Dim objExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Dim xlSheet2 As Excel.Worksheet
Dim xlSheet3 As Excel.Worksheet
Set objExcel = New Excel.Application
Set xlBook = objExcel.Workbooks.Open(sTemplatePath & sTemplateName)
Set xlSheet1 = xlBook.Worksheets("Sheet1")
Set xlSheet2 = xlBook.Worksheets("Sheet2")
Set xlSheet3 = xlBook.Worksheets("Sheet3")
xlBook.Worksheets("Sheet2").Delete
xlBook.Worksheets("Sheet3").Delete
sInvName = sContractNum & " Centralized Bill " & sMonth & " " & sYear & "
Bill.xls"
xlBook.SaveAs (sCentralPath & sInvName)
Set xlSheet1 = Nothing
Set xlSheet2 = Nothing
Set xlSheet3 = Nothing
Set xlBook = Nothing
objExcel.Quit
Set objExcel = Nothing
Thanks for any help.
Kraig