Application starts an instance of Excel but Excel asks to save file after closing worksheet

  • Thread starter Thread starter jonathanrsmall
  • Start date Start date
J

jonathanrsmall

Guest
I have a .net visual basic application which opens an excel spreadsheet, processes data, and then closes the spreadsheet. When I execute the code to close the worksheet, excel displays a save as dialog box. I am not making any changes to any data in the spreadsheet and the application does everything I intend it to do. How do I get excel to just close without asking to save the worksheet?

I Import Microsoft.Office.Interop

Here is the code I am executing:

Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet

xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(xlsFileName)
xlWorkSheet = xlWorkBook.ActiveSheet

Dim range As Excel.Range
range = xlWorkSheet.UsedRange
numberOfDataRecords = range.Rows.Count
numberOfColumns = range.Columns.Count

Dim column_PLAN_ID As Integer = 0
Dim column_VPA_LOCATION As Integer = 0
Dim column_VPA_MEMBER_ID As Integer = 0
Dim column_USER_NAME As Integer = 0
Dim column_WEB_PASSWORD As Integer = 0
Dim columnHeading As String = ""

Dim x As Integer = 0

For x = 1 To numberOfColumns
columnHeading = xlWorkSheet.Cells(1, x).value
If columnHeading.Length > 0 Then
columnHeading = columnHeading.Trim()
End If
If columnHeading = "PLAN_ID" Then
column_PLAN_ID = x
Else
If columnHeading = "VPA_LOCATION" Then
column_VPA_LOCATION = x
Else
If columnHeading = "VPA_MEMBER_ID" Then
column_VPA_MEMBER_ID = x
Else
If columnHeading = "USER_NAME" Then
column_USER_NAME = x
Else
If columnHeading = "WEB_PASSWORD" Then
column_WEB_PASSWORD = x
End If
End If
End If
End If
End If
Next

For x = 2 To numberOfDataRecords
participantPlanID(x - 1) = xlWorkSheet.Cells(x, column_PLAN_ID).value
participantLocation(x - 1) = xlWorkSheet.Cells(x, column_VPA_LOCATION).value
participantMemberID(x - 1) = xlWorkSheet.Cells(x, column_VPA_MEMBER_ID).value
participantUserID(x - 1) = xlWorkSheet.Cells(x, column_USER_NAME).value
participantPassword(x - 1) = xlWorkSheet.Cells(x, column_WEB_PASSWORD).value
Next


xlWorkBook.Close(False)
xlApp.Quit()




jonathan small

Continue reading...
 
Back
Top