cmd看excel有多少个子表_什么win cmd打开特定的电子表格在Excel?

I know that you can open an Excel file from the win cmd line. But how would you open a particular spreadsheet in that file using win cmd?

解决方案Paste the following code into a text editor (NotePad, WordPad, Word

etc)

Save the file with a "vbs" extension, for example

ExcelSheet2.vbs

Change this line strFileName = "c:\temp\testa.xlsx" to your

desired Excel file path

You can then run this from the commandline by entering the path name of your vbs file

The code has error handling in case the filepath is wrong, or a second sheet isn't present.

[Updated: added further error handling to test for the second sheet being hidden]

Const xlVisible = -1

Dim objExcel

Dim objWb

Dim objws

Dim strFileName

strFileName = "c:\temp\test.xlsx"

On Error Resume Next

Set objExcel = CreateObject("excel.application")

Set objWb = objExcel.Workbooks.Open(strFileName)

Set objws = objWb.Sheets(2)

On Error GoTo 0

If Not IsEmpty(objws) Then

If objws.Visible = xlVisible Then

objExcel.Goto objws.Range("a1")

Else

wscript.echo "the 2nd sheet is present but is hidden"

End If

objExcel.Visible = True

Else

objExcel.Quit

Set objExcel = Nothing

If IsEmpty(objWb) Then

wscript.echo strFileName & " not found"

Else

wscript.echo "sheet2 not found"

End If

End If

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值