我写了如下代码,可是推出程序后第一次打开ss.xls总不行,需要打开2次,为什么?
    Dim xlApp As New Excel.Application    'excel 应用    Dim xlSheet As Excel.Worksheet           'excel sheet
        
        xlApp.Workbooks.Open "c:\ss.xls"
        Set xlSheet = xlApp.Worksheets(1)
    With xlApp.ActiveSheet       
    .Cells(1, 1).Value = "aa"
     End With
 xlApp.DisplayAlerts = FalsexlSheet.SaveAs ("C:\ss.xls")
xlApp.Quit
Set xlApp = Nothing

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim xlApp As New Excel.Application    'excel 应用
        Dim xlSheet As Excel.Worksheet           'excel sheet
            xlApp.Workbooks.Open "e:\毕业设计\muban.xls"
            Set xlSheet = xlApp.Worksheets(1)
            xlApp.Visible = True '''''''就是少这段代码
            With xlApp.ActiveSheet
                 .Cells(1, 1).Value = "aa"
            End With
            ' xlApp.DisplayAlerts = False这段代码出掉    xlSheet.SaveAs ("C:\ss.xls")
        xlApp.Quit
        Set xlApp = Nothing
    End Sub
    这样就OK了。不知道是否满足你的要求