如何用VBS删除excel文件多行
(2)DQS.XLS里面只有一张工作表,先删除第一列,再删除第一行到第1000行,提示退出完成
哪位能帮我写一个VBS,谢谢了
不好意思,我要的是VBS,不是VBA,能不能再改一下 展开
我写了个,测试能用。
有二个前提: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同一位置,双击执行便可。
2013-09-03 · 知道合伙人旅游行家
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,能不能再改一下
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盘