- 'test2.vbs
- 'On Error Resume Next
-
- Main
- '************************************************************************
- Sub Main()
- '************************************************************************
-
- Dim objExcel1, objExcel2, strFile1, strFile2
-
- If Excel_Init(objExcel1) <> True Or Excel_Init(objExcel2) <> True Then
- Exit Sub
- End If
-
- strFile1 = "C:\Users\Yu2n\Desktop\新建 Microsoft Office Excel 工作表.xlsm"
- strFile2 = "C:\Users\Yu2n\Desktop\新建 Microsoft Office Excel 工作表 - 副本.xlsm"
-
- objExcel1.Workbooks.Open(strFile1)
- objExcel2.Workbooks.Open(strFile2)
-
- Excel_Show objExcel1, True
- Excel_Show objExcel2, True
-
- End Sub
-
-
- '************************************************************************
- '创建 Excel 对象
- '************************************************************************
- Function Excel_Init(ByRef objExcel)
- Const msoAutomationSecurityLow = 1 '宏有效打开文件,Application 启动初始值。
- Const msoAutomationSecurityByUI = 2 '使用安全性警告对话框中指定的安全级别打开文件。
- Const msoAutomationSecurityForceDisable = 3 '不显示安全性警告对话框,宏无效打开文件。
- On Error Resume Next
- Set objExcel = CreateObject("Excel.Application")
- If Not Err.Number = 0 Then
- Msgbox "错误:无法创建 Excel 对象,你可能没有安装 Excel 。", vbCritical+vbOKOnly, WScript.ScriptName
- WScript.Quit(999)
- End If
- If Not objExcel.Application.Version >= 12.0 Then
- Msgbox "警告:请使用 Office 2007 以上版本。", vbExclamation+vbOKOnly, WScript.ScriptName
- End If
- ' 隐藏运行,屏蔽提示
- Excel_Show objExcel, False
- 'objExcel.AutomationSecurity = msoAutomationSecurityByUI '宏安全性配置
- Excel_Init = (Err.Number = 0)
- End Function
-
- '************************************************************************
- Sub Excel_Show(ByRef objExcel, ByVal blnShowOrHide)
- '************************************************************************
- objExcel.Visible = (blnShowOrHide = True)
- objExcel.DisplayAlerts = (blnShowOrHide = True)
- End Sub
复制代码
|