|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这是 MS 的一示例, 请另存为 *.VBS 文件双击执行, 您 可以在其中对 EXCEL对象 objXL 进行操作:
' Windows Script Host Sample Script ' ' ------------------------------------------------------------------------ ' Copyright (C) 1996 Microsoft Corporation ' ' You have a royalty-free right to use, modify, reproduce and distribute ' the Sample Application Files (and/or any modified version) in any way ' you find useful, provided that you agree that Microsoft has no warranty, ' obligations or liability for any Sample Application Files. ' ------------------------------------------------------------------------
' This sample will display Windows Scripting Host properties in Excel.
L_Welcome_MsgBox_Message_Text = "此脚本将在 Excel 中显示 Windows Scripting Host 属性。" L_Welcome_MsgBox_Title_Text = "Windows Scripting Host 范例" Call Welcome()
' ******************************************************************************** ' * ' * Excel Sample ' * Dim objXL Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = TRUE
objXL.WorkBooks.Add
objXL.Columns(1).ColumnWidth = 20 objXL.Columns(2).ColumnWidth = 30 objXL.Columns(3).ColumnWidth = 40
objXL.Cells(1, 1).Value = "属性名称" objXL.Cells(1, 2).Value = "值" objXL.Cells(1, 3).Value = "说明"
objXL.Range("A1:C1").Select objXL.Selection.Font.Bold = True objXL.Selection.Interior.ColorIndex = 1 objXL.Selection.Interior.Pattern = 1 'xlSolid objXL.Selection.Font.ColorIndex = 2
objXL.Columns("B:B").Select objXL.Selection.HorizontalAlignment = &hFFFFEFDD ' xlLeft
Dim intIndex intIndex = 2
Sub Show(strName, strValue, strDesc) objXL.Cells(intIndex, 1).Value = strName objXL.Cells(intIndex, 2).Value = strValue objXL.Cells(intIndex, 3).Value = strDesc intIndex = intIndex + 1 objXL.Cells(intIndex, 1).Select End Sub
' ' Show WScript properties ' Call Show("Name", WScript.Name, "应用程序昵称") Call Show("Version", WScript.Version, "应用程序版本") Call Show("FullName", WScript.FullName, "应用程序环境: 完整合格的名称") Call Show("Path", WScript.Path, "应用程序环境: 仅包含路径") Call Show("Interactive", WScript.Interactive, "交互模式的状态")
' ' Show command line arguments. ' Dim colArgs Set colArgs = WScript.Arguments Call Show("Arguments.Count", colArgs.Count, "命令行参数数目")
For i = 0 to colArgs.Count - 1 objXL.Cells(intIndex, 1).Value = "Arguments(" & i & ")" objXL.Cells(intIndex, 2).Value = colArgs(i) intIndex = intIndex + 1 objXL.Cells(intIndex, 1).Select Next
' ******************************************************************************** ' * ' * Welcome ' * Sub Welcome() Dim intDoIt
intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _ vbOKCancel + vbInformation, _ L_Welcome_MsgBox_Title_Text ) If intDoIt = vbCancel Then WScript.Quit End If End Sub |
|