简体   繁体   中英

Avoiding “Microsoft Excel” prompt

I'm writing the following bits of code for a SaveFile Dialog box in Visual Basic 2010.NET. The code works well as the XLSX file is created and opens in Microsoft Excel. However, the problem that I am having is that if the program overwrites a file, the user is getting two prompts. One prompt is from the program's own SaveFile dialog confirming the choice. The other is from Microsoft Excel asking you the same. It's as if the program is running in the background.

Does anyone know how I can write this code to save the file as an Excel file?

Imports Excel = Microsoft.Office.Interop.Excel
Public Class Frm1
    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value

    Dim rowcounter As Integer = 1


    xlApp = New Excel.Application
    xlApp.Visible = False
    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkSheet = xlWorkBook.Sheets("Sheet1")
    xlWorkSheet.Cells(rowcounter, rowcounter) = "Something goes here."

    xlWorkSheet.SaveAs(SaveXLS.FileName)

    xlWorkBook.Close()
    xlApp.Quit()
End Class

I think you want DisplayAlerts=false . Take a look at the answer to this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM