如何用vba语句清除另一个工作表的所有内容
答案:1 悬赏:0 手机版
解决时间 2021-02-06 13:57
- 提问者网友:ミ烙印ゝ
- 2021-02-06 02:00
如何用vba语句清除另一个工作表的所有内容
最佳答案
- 五星知识达人网友:几近狂妄
- 2021-02-06 02:05
Option Explicit
Sub test()
Dim pth1 As String
pth1 = "e:\test.xlsx"
clear_wb pth1
End Sub
Private Sub clear_wb(ByVal pth As String)
Dim wb As Workbook, sht As Worksheet
Set wb = Application.Workbooks.Open(pth)
Application.DisplayAlerts = False
For Each sht In wb.Sheets
sht.Cells.Clear
Next sht
wb.Save
wb.Close False
Set wb = Nothing
Application.DisplayAlerts = True
MsgBox "指定工作簿数据清除完毕!"
End Sub
Sub test()
Dim pth1 As String
pth1 = "e:\test.xlsx"
clear_wb pth1
End Sub
Private Sub clear_wb(ByVal pth As String)
Dim wb As Workbook, sht As Worksheet
Set wb = Application.Workbooks.Open(pth)
Application.DisplayAlerts = False
For Each sht In wb.Sheets
sht.Cells.Clear
Next sht
wb.Save
wb.Close False
Set wb = Nothing
Application.DisplayAlerts = True
MsgBox "指定工作簿数据清除完毕!"
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯