如何让它自动“重写”我试图保存的.xlsx文件?

时间:2013-05-01 14:37:12

标签: excel vb.net-2010

所以,我有以下代码将高分保存到excel文件中,它有效,我只有一个问题,它总是询问我是否要重写现有的xlsx文件,我怎么能让它自动说是的它,还是有其他方法来保存xlsx文件,所以它不问这个问题?

Imports EXC = Microsoft.Office.Interop.Excel

Private Sub highscoreSave()
    Dim app As EXC.Application
    Dim ws As EXC.Worksheet, wb As EXC.Workbook
    app = New EXC.Application()
    app.Visible = False
    wb = app.Workbooks.Open(My.Application.Info.DirectoryPath.ToString & "\highscore.xlsx")
    ws = wb.Worksheets(1)
    For index As Integer = 1 To 11
        ws.Cells(index, 1).Value = lst_name(index - 1)
        ws.Cells(index, 2).Value = lst_score(index - 1)
    Next
    wb.Save()
    wb.Close()
    app.Quit()
End Sub

2 个答案:

答案 0 :(得分:0)

使用

Application.DisplayAlerts = False

但是在退出程序之前不要忘记重新打开它们......

Application.DisplayAlerts = True

答案 1 :(得分:0)

要禁止向用户发送消息:

Application.DisplayAlerts = False