vb运行总提示在当前位置发现已存在excel文件
PrivateSubCommand1_Click()Doi=1SetxlApp=CreateObject("Excel.Application")'创建EXCEL应用类x...
Private Sub Command1_Click()
Do
i = 1
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = False '设置EXCEL不可见
Set xlBook = xlApp.Workbooks.Open("c:\Users\Administrator\Desktop\1.xlsx") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(i) '打开EXCEL工作表
xlsheet.Activate '激活工作表
xlsheet.Cells(1, 1) = 1
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
i = i + 1
Loop Until i = 3
End Sub 展开
Do
i = 1
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = False '设置EXCEL不可见
Set xlBook = xlApp.Workbooks.Open("c:\Users\Administrator\Desktop\1.xlsx") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(i) '打开EXCEL工作表
xlsheet.Activate '激活工作表
xlsheet.Cells(1, 1) = 1
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
i = i + 1
Loop Until i = 3
End Sub 展开
展开全部
Private Sub Command1_Click()
Application.DisplayAlerts = False
i = 1
Do
Set xlApp = CreateObject("Excel.Application") '´´½¨EXCELÓ¦ÓÃÀà
xlApp.Visible = False 'ÉèÖÃEXCEL²»¿É¼û
Set xlBook = xlApp.Workbooks.Open("c:\Users\Administrator\Desktop\1.xlsx") '´ò¿ªEXCEL¹¤×÷²¾
Set xlsheet = xlBook.Worksheets(i) '´ò¿ªEXCEL¹¤×÷±í
xlsheet.Activate '¼¤»î¹¤×÷±í
xlsheet.Cells(1, 1) = 1
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
i = i + 1
Loop Until i = 3
Application.DisplayAlerts = True
End Sub
修改说明:
1、i=1应该放在do之外,不然成死循环了。
2、
在代码首尾分别加
Application.DisplayAlerts = False
Application.DisplayAlerts = True
保存时就不再弹出对话框了。
Application.DisplayAlerts = False
i = 1
Do
Set xlApp = CreateObject("Excel.Application") '´´½¨EXCELÓ¦ÓÃÀà
xlApp.Visible = False 'ÉèÖÃEXCEL²»¿É¼û
Set xlBook = xlApp.Workbooks.Open("c:\Users\Administrator\Desktop\1.xlsx") '´ò¿ªEXCEL¹¤×÷²¾
Set xlsheet = xlBook.Worksheets(i) '´ò¿ªEXCEL¹¤×÷±í
xlsheet.Activate '¼¤»î¹¤×÷±í
xlsheet.Cells(1, 1) = 1
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
i = i + 1
Loop Until i = 3
Application.DisplayAlerts = True
End Sub
修改说明:
1、i=1应该放在do之外,不然成死循环了。
2、
在代码首尾分别加
Application.DisplayAlerts = False
Application.DisplayAlerts = True
保存时就不再弹出对话框了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询