English 中文(简体)
在Excel开立特殊电子表格的获胜点是什么?
原标题:What the win cmd to open a particular spreadsheet in Excel?

我知道,你可以从双赢线开立一个Excel文档。 但是,你如何利用双赢的圆顶打开一个特定的电子表格?

最佳回答
  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: emp esta.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]

sample

Const xlVisible = -1
Dim objExcel
Dim objWb
Dim objws
Dim strFileName
strFileName = "c:	emp	est.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
问题回答

或者,你可以从指挥线开出工作手册,在《工作手册》中添加以下代码,以启动“Sheet2”

Private Sub Workbook_Open()

    ThisWorkbook.Sheets("Sheet2").Activate

End Sub

你们需要确保《工作手册》处于一个可信赖的地点,而安全环境允许宏观运行。 @brettdj的解决方案比以前好得多,但这是一种替代办法。





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签