Imports System Imports System.Diagnostics Private Sub printdocument1_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles printdocument1.EndPrint Do While True 'kill all resident excels in memory with extreme prejudice If CloseAllResidentExcels() = True Then Exit Do End If Loop 'reinit your vars here xlApp = CType(CreateObject("Excel.Application"), Excel.Application) wbkToShow = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet) wshToShow = DirectCast(wbkToShow.Worksheets("Sheet1"), Excel.Worksheet) End Sub Private Function CloseAllResidentExcels() As Boolean CloseAllResidentExcels = False Try 'loop this process until there are no valid id's to return Dim Prc As Process Dim localByName As Process() = Process.GetProcessesByName("EXCEL") Prc = Process.GetProcessById(localByName(0).Id) Prc.Kill() Catch ex As Exception CloseAllResidentExcels = True End Try End Function
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE