什么win cmd打开特定的电子表格在Excel? [英] What the win cmd to open a particular spreadsheet in Excel?

查看:1114
本文介绍了什么win cmd打开特定的电子表格在Excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以从win cmd行打开一个Excel文件。但是,如何使用win cmd打开该文件中的特定电子表格?

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?

推荐答案



  1. 使用vbs扩展名保存文件,例如

    ExcelSheet2.vbs

  2. 更改此行 strFileName =c:\temp\testa.xlsx到您的
    所需的Excel文件路径

  3. 然后,您可以通过输入vbs文件的路径名从命令行运行

  1. Paste the following code into a text editor (NotePad, WordPad, Word etc)
  2. Save the file with a "vbs" extension, for example
    ExcelSheet2.vbs
  3. Change this line strFileName = "c:\temp\testa.xlsx" to your desired Excel file path
  4. 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

这篇关于什么win cmd打开特定的电子表格在Excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆