我需要一个vbs新建一个空白的excel表格到指定路径的代码,但不知道怎么写,希望谢谢
3个回答
展开全部
sub createExcel(path,name) '定义一个生成excel文件的子过程,path为你要的指定路径,name为excel文件想要的名字
dim excel
set excel = createobject("excel.application")
excel.Workbooks.Add
excel.Save path & name & ".xls"
end Sub
createExcel "c:\","my" '这里是调用子过程生成指定路径下指定名字的excel文件
dim excel
set excel = createobject("excel.application")
excel.Workbooks.Add
excel.Save path & name & ".xls"
end Sub
createExcel "c:\","my" '这里是调用子过程生成指定路径下指定名字的excel文件
更多追问追答
追问
你好,谢谢你的回答,文件能创建了,但是在打开的时候说格式不对,而且我写的vbs没有办法写数据进去,如果可以的话在帮我看看,谢谢
追答
没办法啊,用vbs新建excel文件多数都是类似的方法,格式不对也只能点yes确认后打开了。
至于你没办法写数据?你问题也没说啊。不知道你想写什么。我可以再回答你一次追问!
展开全部
sub createExcel(Xpath,Xname) '定义一个生成excel文件的子过程,Xpath为你要的指定路径,Xname为excel文件想要的名字
dim excel
set excel = createobject("excel.application")
excel.Workbooks.Add()
excel.ActiveWorkbook.SaveAs Xpath & Xname & ".xls"
excel.Quit
Set excel=Nothing
end Sub
Xpath=InputBox("请输入excel文件保存地址以\结束,例如:E:\文档\","提示")
Xname=InputBox("请输入excel文件名称,例如:资源明细","提示")
createExcel Xpath,Xname '这里是调用子过程生成指定路径下指定名字的excel文件
dim excel
set excel = createobject("excel.application")
excel.Workbooks.Add()
excel.ActiveWorkbook.SaveAs Xpath & Xname & ".xls"
excel.Quit
Set excel=Nothing
end Sub
Xpath=InputBox("请输入excel文件保存地址以\结束,例如:E:\文档\","提示")
Xname=InputBox("请输入excel文件名称,例如:资源明细","提示")
createExcel Xpath,Xname '这里是调用子过程生成指定路径下指定名字的excel文件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码如下,貌似这有这个办法发上来了
Dim WebAddress
Dim IP
Dim bytebig
Dim delay
Dim TTL
Dim i,FileName
Dim filena,fso
Set pExcel = CreateObject("Excel.Application")
Set fso = CreateObject("scripting.FileSystemObject")
WebAddress=InputBox("请输入你要ping的网络地址","Ping 测试","10.71.17.115")
cs=InputBox("请输入你要ping次数","Ping 测试","10")
yanshi=InputBox("请输入等待时间,安秒计时","Ping 测试","3")
yanshi2=yanshi*1000
FileName="c:\Ping.xlsx"
pExcel.Workbooks.Open FileName
for i = 1 to cs
If WebAddress <> "" Then
Set OBJWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPings = OBJWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" &WebAddress& "'")
For Each OBJStatus in colPings
If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
pExcel.worksheets ("sheet1").Cells(i, 1).VAlue = "Off Line"
pExcel.worksheets ("sheet1").Cells(i, 5).VAlue = now
wscript.sleep yanshi2
Else
IP=WebAddress
bytebig=OBJStatus.BufferSize
delay=OBJStatus.ResponseTime
TTL=OBJStatus.ResponseTimeToLive
pExcel.worksheets ("sheet1").Cells(i, 1).VAlue = IP
pExcel.worksheets ("sheet1").Cells(i, 2).VAlue = bytebig
pExcel.worksheets ("sheet1").Cells(i, 3).VAlue = delay
pExcel.worksheets ("sheet1").Cells(i, 4).VAlue = TTL
pExcel.worksheets ("sheet1").Cells(i, 5).VAlue = now
wscript.sleep yanshi2
end if
next
End If
next
pExcel.ActiveWorkbook.Save()
pExcel.Workbooks.Close()
pExcel.Quit()
msgbox ("It's OK")
Dim WebAddress
Dim IP
Dim bytebig
Dim delay
Dim TTL
Dim i,FileName
Dim filena,fso
Set pExcel = CreateObject("Excel.Application")
Set fso = CreateObject("scripting.FileSystemObject")
WebAddress=InputBox("请输入你要ping的网络地址","Ping 测试","10.71.17.115")
cs=InputBox("请输入你要ping次数","Ping 测试","10")
yanshi=InputBox("请输入等待时间,安秒计时","Ping 测试","3")
yanshi2=yanshi*1000
FileName="c:\Ping.xlsx"
pExcel.Workbooks.Open FileName
for i = 1 to cs
If WebAddress <> "" Then
Set OBJWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPings = OBJWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" &WebAddress& "'")
For Each OBJStatus in colPings
If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
pExcel.worksheets ("sheet1").Cells(i, 1).VAlue = "Off Line"
pExcel.worksheets ("sheet1").Cells(i, 5).VAlue = now
wscript.sleep yanshi2
Else
IP=WebAddress
bytebig=OBJStatus.BufferSize
delay=OBJStatus.ResponseTime
TTL=OBJStatus.ResponseTimeToLive
pExcel.worksheets ("sheet1").Cells(i, 1).VAlue = IP
pExcel.worksheets ("sheet1").Cells(i, 2).VAlue = bytebig
pExcel.worksheets ("sheet1").Cells(i, 3).VAlue = delay
pExcel.worksheets ("sheet1").Cells(i, 4).VAlue = TTL
pExcel.worksheets ("sheet1").Cells(i, 5).VAlue = now
wscript.sleep yanshi2
end if
next
End If
next
pExcel.ActiveWorkbook.Save()
pExcel.Workbooks.Close()
pExcel.Quit()
msgbox ("It's OK")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询