Click here to Skip to main content
15,887,427 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
kanchoette31-Jan-09 2:05
kanchoette31-Jan-09 2:05 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
Wendelius31-Jan-09 2:26
mentorWendelius31-Jan-09 2:26 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
kanchoette31-Jan-09 3:10
kanchoette31-Jan-09 3:10 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
Wendelius31-Jan-09 3:17
mentorWendelius31-Jan-09 3:17 
QuestionEdit Vista file properties details with VBA Pin
piralko30-Jan-09 22:38
piralko30-Jan-09 22:38 
QuestionPopulating from one combobox to another combobox in VB.NET [modified] Pin
kishore1530-Jan-09 20:06
kishore1530-Jan-09 20:06 
AnswerRe: Populating from one combobox to another combobox in VB.NET Pin
Christian Graus30-Jan-09 20:23
protectorChristian Graus30-Jan-09 20:23 
QuestionUnable to close or kill the Excel Application EXE in the Task Manager through code. Pin
manoharbalu30-Jan-09 18:35
manoharbalu30-Jan-09 18:35 
I have placed my Code below. Everything works fine except that the Excel application is running at the backgroung even after quitting the Excel using code also setting the Excel object to Nothing. But the Excel application terminates on closing the application.

When I click the button for the first time, the excel application appears in the task manager, but is not closing. But when I click the button for the second time a second Excel application instance appears in the task manager, but it closes immediately when I set the Excel object to "Nothing".

Anybody, pls suggest me how to close the excel instance which is created for the first time.

Private Sub ExportExcel_Click()
Dim objExcel As Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objwksSheet As Excel.Worksheet

Dim Msg, style, Title, Response
style = vbYesNoCancel + vbQuestion + vbDefaultButton2 ' Define buttons.
Msg = "Before Exporting the Tags to Excel, all the unsaved Excel Files must be closed. Are you sure you want to Continue?"
Title = "PV Trend" ' Define title.
Response = MsgBox(Msg, style, Title)
If Response = vbNo Or Response = vbCancel Then ' User chose No.
Exit Sub
End If

Dim i As Long
Dim n As Long
Dim gridChart As ChartObject
Dim tagdataChart As Chart
Dim curentChart As Object


If SelTagsCnt <= 0 Then
MsgBox "No Tags are there to export"
Exit Sub
End If
'***************************************************************
' create new hidden instance of Excel and open its workbooks collection
If DebugMode = True Then
xlsfilename = "c:\testExcel.xls"
Else
xlsfilename = glbSysPath & "esim\Model\" & ModelName & _
"\Instructor\PVTREND" & ModelName & ".xls"
End If
' Set objExcel = New Excel.Application
' objExcel.Workbooks.Open xlsfilename
' objExcel.Worksheets("Sheet1").Activate
' objExcel.DisplayAlerts = False

' With objExcel
' .ActiveWorkbook.Save FileName:= _
' xlsfilename, _
' FileFormat:=xlNormal, Password:="", _
' WriteResPassword:="", ReadOnlyRecommended:=False, _
' CreateBackup:=False
'
' .ActiveWindow.Close
' End With
'*******************************************************************

On Error Resume Next
'Call EmpMSFgrid_load
'Set objExcel = GetObject(, "Excel.Application")
Set objExcel = New Excel.Application
' If Err.Number Then
' Err.Clear
' Set objExcel = CreateObject("Excel.Application")
' If Err.Number Then
' MsgBox "Unable to open Excel Application."
' End If
' End If
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add

objExcel.Worksheets("sheet1").Activate

xlAPP.Worksheets("Sheet1").Range (strRangeXVal)

' Merging the First 3 Rows
With objWorkbook.Sheets("Sheet1")
For i = 1 To 3
.Range(.Cells(i, 1), .Cells(i, 50)).Select
Selection.Merge
Next i
End With

' Add Heading "PROSIMULATOR HISTORICAL PV TREND PLOT" in the First Row of the Excel File
objWorkbook.ActiveSheet.Cells(1, 1).Font.Bold = True
objWorkbook.ActiveSheet.Cells(1, 1).Font.Size = 18
objWorkbook.ActiveSheet.Cells(1, 1).Font.Color = RGB(0, 0, 255)
objWorkbook.ActiveSheet.Cells(1, 1).Value = " PROSIMULATOR HISTORICAL PV TREND PLOT"
objWorkbook.ActiveSheet.Cells(1, 1).Interior.Color = RGB(255, 128, 0) 'RGB(185, 185, 185)

' Format 2nd Row
objWorkbook.ActiveSheet.Cells(2, 1).Font.Bold = True
objWorkbook.ActiveSheet.Cells(2, 1).Font.Size = 11
objWorkbook.ActiveSheet.Cells(2, 1).Font.Color = RGB(41, 11, 164)
objWorkbook.ActiveSheet.Cells(2, 1).Value = "Model Name:" & ModelName
'objWorkbook.ActiveSheet.Cells(2, 1).Interior.Color = RGB(137, 200, 237)

objWorkbook.SaveCopyAs xlsfilename
' .ActiveWorkbook.SaveAs FileName:= _
' xlsfilename
objWorkbook.Close savechanges:=False

objWorkbook.Close
'Set objWorkbook = Nothing
objExcel.Visible = False
objExcel.ActiveWindow.Close
objExcel.Quit
objExcel.Application.Quit

' End With

Dim sTitle As String
Dim iHwnd As Integer
Dim ihTask As Integer
Dim iReturn As Integer
sTitle = "EXCEL"
iHwnd = FindWindow(0&, sTitle)
iReturn = PostMessage(objExcel.hWnd, WM_QUIT, 0, 0)

Set objWorkbook = Nothing
Set objExcel = Nothing
Set curentChart = Nothing
Set tagdataChart = Nothing
Set gridChart = Nothing

End Sub


AnswerRe: Unable to close or kill the Excel Application EXE in the Task Manager through code. Pin
Dave Kreskowiak31-Jan-09 4:22
mveDave Kreskowiak31-Jan-09 4:22 
Questionhelp file creation Pin
ngugi30-Jan-09 5:36
ngugi30-Jan-09 5:36 
AnswerRe: help file creation Pin
Dave Kreskowiak30-Jan-09 6:18
mveDave Kreskowiak30-Jan-09 6:18 
QuestionShareware Application Pin
ivo7530-Jan-09 3:00
ivo7530-Jan-09 3:00 
AnswerRe: Shareware Application Pin
Ashfield30-Jan-09 4:23
Ashfield30-Jan-09 4:23 
GeneralRe: Shareware Application Pin
EliottA30-Jan-09 4:25
EliottA30-Jan-09 4:25 
QuestionWindows Media Player cannot open MP3 files Pin
tatchung30-Jan-09 0:58
tatchung30-Jan-09 0:58 
AnswerRe: Windows Media Player cannot open MP3 files Pin
Eddy Vluggen30-Jan-09 1:05
professionalEddy Vluggen30-Jan-09 1:05 
GeneralRe: Windows Media Player cannot open MP3 files Pin
tatchung30-Jan-09 18:42
tatchung30-Jan-09 18:42 
GeneralRe: Windows Media Player cannot open MP3 files Pin
Christian Graus30-Jan-09 18:55
protectorChristian Graus30-Jan-09 18:55 
GeneralRe: Windows Media Player cannot open MP3 files Pin
tatchung1-Feb-09 2:07
tatchung1-Feb-09 2:07 
QuestionRe: Windows Media Player cannot open MP3 files Pin
Eddy Vluggen30-Jan-09 22:41
professionalEddy Vluggen30-Jan-09 22:41 
AnswerRe: Windows Media Player cannot open MP3 files Pin
tatchung1-Feb-09 17:25
tatchung1-Feb-09 17:25 
Questionwhile images are loading if i try to close application its not closing Pin
sham s30-Jan-09 0:28
sham s30-Jan-09 0:28 
AnswerRe: while images are loading if i try to close application its not closing Pin
Dave Kreskowiak30-Jan-09 2:15
mveDave Kreskowiak30-Jan-09 2:15 
GeneralRe: while images are loading if i try to close application its not closing Pin
Luc Pattyn30-Jan-09 3:19
sitebuilderLuc Pattyn30-Jan-09 3:19 
QuestionShell and Sendkeys Problem Pin
Nanda_MR29-Jan-09 22:54
Nanda_MR29-Jan-09 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.