Using VB.NET in Visual Studio 2008, I'm trying to use an Excel spreadsheet as data storage for a simple program. The entire application code is attached below.
In Windows XP, this works exactly as intended. However, in Windows 7, when the application goes to save the data to the spreadsheet, I get a Save dialog prompting me to save the spreadsheet as a copy.
I want the Excel portion to be transparent to the user, as it is when the program is run under XP. Does anyone have any suggestions for a quick fix?
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Dim x As Integer = 0
If Not (txtFirstName.Text = "" Or txtLastName.Text = "" Or txtCompany.Text = "" Or txtEmail.Text = "") Then
Dim xcApp As Excel.Application
Dim xcWB As Excel.Workbook
Dim xcWS As Excel.Worksheet
Dim LastRow As Integer = 2
Dim FirstName, LastName, Email, Company, Title, Phone As String
FirstName = txtFirstName.Text
LastName = txtLastName.Text
Email = txtEmail.Text
Company = txtCompany.Text
Title = txtTitle.Text
Phone = txtPhone.Text
xcApp = New Excel.ApplicationClass
xcWB = xcApp.Workbooks.Open("C:\Data.xlsx")
xcWS = xcWB.Worksheets("sheet1")
LastRow = xcWS.Cells(1, 10).value
xcWS.Cells(LastRow, 1).value = FirstName
xcWS.Cells(LastRow, 2).value = LastName
xcWS.Cells(LastRow, 3).value = Email
xcWS.Cells(LastRow, 4).value = Company
xcWS.Cells(LastRow, 5).value = Title
xcWS.Cells(LastRow, 6).value = Phone
LastRow = LastRow + 1
xcWS.Cells(1, 10).value = LastRow
txtFirstName.Text = ""
txtLastName.Text = ""
txtEmail.Text = ""
txtCompany.Text = ""
txtTitle.Text = ""
txtPhone.Text = ""
x = MsgBox("Please fill out all required fields.", vbOKOnly, "Required fields empty")
Private Sub releaseObject(ByVal obj As Object)
obj = Nothing
Catch ex As Exception
obj = Nothing