我想要做的是从LaTeX生成的PDF中打开某个工作表上的Excel文件,其中包括\href{run:./xx.xls}
。编辑.vbs接受参数
我发现下面的VBScript代码(通过@brettdj)对于用指定文件名打开.vbs文件非常有帮助。 但是如何让代码在每次执行时接受一个参数(打开一个不同的文件),而不是在strFileName
中指定文件名?
Const xlVisible = -1
Dim objExcel
Dim objWb
Dim objws
Dim strFileName
strFileName = "E:RoomContentsAll.xls"
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
您设置'strFileName = WScript.Arguments(0)'然后执行当脚本传递文件名作为第一个命令行参数。见http://ss64.com/vb/arguments.html – Lankymart