我有这个代码
但是当我想打开1.xls时,遇到一个错误,我应该单击“确定”以关闭该错误并打开excel文件。 因为此代码将从互联网上下载Excel文件,所以下载的文件将出现此问题
我正在寻找一种看不到此错误的方法,否则应用程序会自动单击“确定”。
Dim wkb1 As Workbook
Dim sht1 As Worksheet
Dim wkb2 As Workbook
Dim sht2 As Worksheet
Application.ScreenUpdating = False
Set wkb1 = Workbooks.Open("C:\Users\Envid\Desktop\1.xls")
Set wkb2 = ThisWorkbook
Set sht1 = wkb1.Sheets("sheet name")
Set sht2 = wkb2.Sheets(wsname)
sht1.Cells.copy
sht2.Range("A1").PasteSpecial Paste:=xlPasteValues
sht2.Range("A1").PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
wkb1.Close True
Kill ("C:\Users\Envid\Desktop\1.xls")
Application.ScreenUpdating = True
答案 0 :(得分:1)
要简单地阻止警报显示,您可以使用以下
['Oases | Define Oases at Dictionary.com',
'oases - Yahoo Dictionary',
'OASES Cambridge Dictionary',
'Oases - Wikipedia',
'Oases definition and meaning | Collins English Dictionary',
'OASES - YouTube',
'Oases - definition of oases by The Free Dictionary',
'Oases - Correct Spelling - Grammarist',
'Online Tutoring Management & Scheduling Software | Oases',
'OASES - Log in']
['https://www.dictionary.com/browse/oases',
'https://dictionary.yahoo.com/dictionary?p=oases',
'https://dictionary.cambridge.org/zht/%E8%A9%9E%E5%85%B8/%E8%8B%B1%E8%AA%9E/oases',
'https://en.wikipedia.org/wiki/Oasis',
'https://www.collinsdictionary.com/dictionary/english/oases',
'https://www.youtube.com/watch?v=K5gJVgIZgYQ',
'https://www.thefreedictionary.com/oases',
'https://grammarist.com/spelling/oases/',
'https://oasesonline.com/',
'https://oases.wageningenacademic.com/']
但是一旦您越过要添加警报的行,请将其重新设置为True,这样您就可以捕获任何意外警报。
我认为这是您要避免发出警报的Application.DisplayAlerts = False
行,因此请按如下所示进行修改:
wkb1.Close