如何用VBS删除excel文件多行
答案:4 悬赏:40 手机版
解决时间 2021-01-17 05:48
- 提问者网友:半生酒醒
- 2021-01-16 15:57
如何用VBS删除excel文件多行
最佳答案
- 五星知识达人网友:污到你湿
- 2021-01-16 16:03
注:Range("A1").EntireColumn.Delete 这样是删除A1整列
Range("A1").EntireRow.Delete 这样是删除A1整行
Range("A1").Delete 这是删除A1单元格 A2单元格会移上去
上述命令就好像 你选中A1单元格后,右击选择 -》删除 ,在弹出对话框中有四个选项
全部回答
- 1楼网友:洎扰庸人
- 2021-01-16 19:31
Sub LKJLK()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open Filename:=ThisWorkbook.Path & "DQS.XLS"
Set sht = ActiveWorkbook.Sheets(1)
sht.Columns("A:A").Delete
sht.Rows("1:1000").Delete
ActiveWindow.Close True
Application.ScreenUpdating = True
MsgBox "操作完成"
End Sub追问不好意思,我要的是VBS,不是VBA,能不能再改一下追答Dim Ex, Wb, Sht
Set Ex = CreateObject("Excel.Application")
Set Wb = Ex.Workbooks.Open("D:DQS.xls")
Set Sht = Wb.Sheets("Sheet1")
Sht.Columns("a:a").Delete
Sht.Rows("1:1000").Delete
Ex.ActiveWorkbook.Save
MsgBox "操作完成"
Ex.Quit
假设文件在D盘
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open Filename:=ThisWorkbook.Path & "DQS.XLS"
Set sht = ActiveWorkbook.Sheets(1)
sht.Columns("A:A").Delete
sht.Rows("1:1000").Delete
ActiveWindow.Close True
Application.ScreenUpdating = True
MsgBox "操作完成"
End Sub追问不好意思,我要的是VBS,不是VBA,能不能再改一下追答Dim Ex, Wb, Sht
Set Ex = CreateObject("Excel.Application")
Set Wb = Ex.Workbooks.Open("D:DQS.xls")
Set Sht = Wb.Sheets("Sheet1")
Sht.Columns("a:a").Delete
Sht.Rows("1:1000").Delete
Ex.ActiveWorkbook.Save
MsgBox "操作完成"
Ex.Quit
假设文件在D盘
- 2楼网友:思契十里
- 2021-01-16 18:00
Private Sub filesexcel_Click()
Dim fd As Object
Dim fso As Object
Dim mydir As String
Set fso = CreateObject("Scripting.FileSystemObject")
'开启Excel内建的资料夹浏览方块
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then
LookIn = fd.SelectedItems(1)
mydir = fd.SelectedItems(1)
mydir = mydir & ""
Else
MsgBox "您未选择浏览目标文件夹!", 48, "系统提示": Exit Sub
End If
Application.ScreenUpdating = False
Dim i As Long
Dim strName As String
Dim strNewNme As String
nm = Dir(mydir & "DQS.XLS")
Application.DisplayAlerts = False
If nm = "DQS.XLS" Then
Workbooks.Open Filename:=mydir & "DQS.XLS"
Application.Columns("A:A").Delete Shift:=xlToLeft
Application.Rows("1:1000").Delete Shift:=xlUp
MsgBox "DQS.XLS里面只有一张工作表,先删除第一列,再删除第一行到第1000行"
Else
MsgBox "您选择的目录没有DQS.XLS文件!", vbQuestion, Title:="系统信息"
End If
End Sub
追问不好意思,我要的是VBS,不是VBA,能不能再改一下
Dim fd As Object
Dim fso As Object
Dim mydir As String
Set fso = CreateObject("Scripting.FileSystemObject")
'开启Excel内建的资料夹浏览方块
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then
LookIn = fd.SelectedItems(1)
mydir = fd.SelectedItems(1)
mydir = mydir & ""
Else
MsgBox "您未选择浏览目标文件夹!", 48, "系统提示": Exit Sub
End If
Application.ScreenUpdating = False
Dim i As Long
Dim strName As String
Dim strNewNme As String
nm = Dir(mydir & "DQS.XLS")
Application.DisplayAlerts = False
If nm = "DQS.XLS" Then
Workbooks.Open Filename:=mydir & "DQS.XLS"
Application.Columns("A:A").Delete Shift:=xlToLeft
Application.Rows("1:1000").Delete Shift:=xlUp
MsgBox "DQS.XLS里面只有一张工作表,先删除第一列,再删除第一行到第1000行"
Else
MsgBox "您选择的目录没有DQS.XLS文件!", vbQuestion, Title:="系统信息"
End If
End Sub
- 3楼网友:孤独入客枕
- 2021-01-16 17:34
我写了个,测试能用。
有二个前提:1、DQS.XLS文件与VBS文件在同一文件夹内;2、在用VBS操作DQS.XLS时,确保DQS.XLS存在,而且没有被打开。
删除成功后,会提示“操作完成”
具体代码:
dim FsoSetmp
dim FSetmp
dim WSetmp
dim SSetmp
dim a
a = left(wscript.scriptfullname,instrrev(wscript.scriptfullname,"")-1)
set FsoSetmp = CreateObject("Scripting.FileSystemObject")
Set FSetmp = CreateObject("Excel.Application")
Set WSetmp = FSetmp.workbooks.open(a &"DQS.XLS")
set SSetmp = FSetmp.worksheets(1)
with SSetmp
.Columns("A:A").Delete
.Rows("1:1000").Delete
end with
WSetmp.close True
FSetmp.quit
Msgbox "操作完成"
-----------------------------------------------------------------------
具体文件,请下载附件,将文件放在DQS.XLS同一位置,双击执行便可。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯