'1 判斷A.Xls文件是否存在 Sub W1() If Len(Dir('d:/A.xls')) = 0 Then MsgBox 'A文件不存在' Else MsgBox 'A文件存在' End If End Sub '2 判斷A.Xls文件是否打開(kāi) Sub W2() Dim X As Integer For X = 1 To Windows.Count If Windows(X).Caption = 'A.XLS' Then MsgBox 'A文件打開(kāi)了' Exit Sub End If Next End Sub
'3 excel文件新建和保存 Sub W3() Dim wb As Workbook Set wb = Workbooks.Add wb.Sheets('sheet1').Range('a1') = 'abcd' wb.SaveAs 'D:/B.xls' End Sub '4 excel文件打開(kāi)和關(guān)閉
Sub w4() Dim wb As Workbook Set wb = Workbooks.Open('D:/B.xls') MsgBox wb.Sheets('sheet1').Range('a1').Value wb.Close False End Sub '5 excel文件保存和備份 Sub w5() Dim wb As Workbook Set wb = ThisWorkbook wb.Save wb.SaveCopyAs 'D:/ABC.xls' End Sub
'6 excel文件復(fù)制和刪除 Sub W6() FileCopy 'D:/ABC.XLS', 'E:/ABCd.XLS' Kill 'D:/ABC.XLS' End Sub |
|
來(lái)自: L羅樂(lè) > 《全民學(xué)VBA》