`

Microsoft Excel Scripts

 
阅读更多

http://www.activexperts.com/network-monitor/windowsmanagement/scripts/msoffice/excel/

 

Add Data to a Spreadsheet Cell


Demonstration script that adds the words "Test Value" to cell 1,1 in a new spreadsheet.

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Test value"
	

Add Formatted Data to a Spreadsheet


Demonstration script that adds the words "test value" to a new spreadsheet, then formats the cell containing the value.

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Test value"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Font.Size = 24
objExcel.Cells(1, 1).Font.ColorIndex = 3
	

Create User Accounts Based on Information in a Spreadsheet


Demonstration script that creates new Active Directory user accounts based on information stored in an Excel spreadsheet.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("C:\Scripts\New_users.xls")

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
    Set objOU = GetObject("ou=Finance, dc=fabrikam, dc=com")
    Set objUser = objOU.Create _
        ("User", "cn=" & objExcel.Cells(intRow, 1).Value)
    objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
    objUser.GivenName = objExcel.Cells(intRow, 3).Value
    objUser.SN = objExcel.Cells(intRow, 4).Value
    objUser.AccountDisabled = FALSE
    objUser.SetInfo
    intRow = intRow + 1
Loop

objExcel.Quit
	

Format a Range of Cells


Demonstration script that adds data to four different cells in a spreadsheet, then uses the Range object to format multiple cells at the same time.

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = "Name"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Interior.ColorIndex = 30
objExcel.Cells(1, 1).Font.ColorIndex = 2
objExcel.Cells(2, 1).Value = "Test value 1"
objExcel.Cells(3, 1).Value = "Test value 2"
objExcel.Cells(4, 1).Value = "Tets value 3"
objExcel.Cells(5, 1).Value = "Test value 4"

Set objRange = objExcel.Range("A1","A5")
objRange.Font.Size = 14

Set objRange = objExcel.Range("A2","A5")
objRange.Interior.ColorIndex = 36

Set objRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
	

List Active Directory Data in a Spreadsheet


Demonstration script that retrieves data from Active Directory and then displays that data in an Excel spreadsheet.

Const ADS_SCOPE_SUBTREE = 2

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = "Last name"
objExcel.Cells(1, 2).Value = "First name"
objExcel.Cells(1, 3).Value = "Department"
objExcel.Cells(1, 4).Value = "Phone number"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
objCommand.CommandText = _
    "SELECT givenName, SN, department, telephoneNumber FROM " _
        & "'LDAP://dc=fabrikam,dc=microsoft,dc=com' WHERE " _
            & "objectCategory='user'"  
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x = 2

Do Until objRecordSet.EOF
    objExcel.Cells(x, 1).Value = _
        objRecordSet.Fields("SN").Value
    objExcel.Cells(x, 2).Value = _
        objRecordSet.Fields("givenName").Value
    objExcel.Cells(x, 3).Value = _
        objRecordSet.Fields("department").Value
    objExcel.Cells(x, 4).Value = _
        objRecordSet.Fields("telephoneNumber").Value
    x = x + 1
    objRecordSet.MoveNext
Loop

Set objRange = objExcel.Range("A1")
objRange.Activate

Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()

Set objRange = objExcel.Range("B1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()

Set objRange = objExcel.Range("C1")
objRange.Activate

Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()

Set objRange = objExcel.Range("D1")
objRange.Activate

Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()

Set objRange = objExcel.Range("A1").SpecialCells(11)
Set objRange2 = objExcel.Range("C1")
Set objRange3 = objExcel.Range("A1")
	

List Excel Color Values


Demonstration script that displays the various colors -- and their related color index -- available when programmatically controlling Microsoft Excel.

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add

For i = 1 to 56
    objExcel.Cells(i, 1).Value = i
    objExcel.Cells(i, 1).Interior.ColorIndex = i
Next
	

List Service Data in a Spreadsheet


Demonstration script that retrieves information about each service running on a computer, and then displays that data in an Excel spreadsheet.

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

x = 1
strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * From Win32_Service")

For Each objService in colServices
    objExcel.Cells(x, 1) = objService.Name
    objExcel.Cells(x, 2) = objService.State
    x = x + 1
Next
	

Open an Excel Spreadsheet


Demonstration script that opens an existing Excel spreadsheet named C:\Scripts\New_users.xls.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\New_users.xls")
	

Read an Excel Spreadsheet


Demonstration script that reads the values stored in a spreadsheet named C:\Scripts\New_users.xls.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("C:\Scripts\New_users.xls")

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
    Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).Value
    Wscript.Echo "sAMAccountName: " & objExcel.Cells(intRow, 2).Value
    Wscript.Echo "GivenName: " & objExcel.Cells(intRow, 3).Value
    Wscript.Echo "LastName: " & objExcel.Cells(intRow, 4).Value
    intRow = intRow + 1
Loop

objExcel.Quit
	
分享到:
评论

相关推荐

    【Python3+VBA】在Excel中生成小姐姐.pdf

    VBA是Microsoft Office套件中的一个组件,主要用于自动化Office应用程序如Excel、Word等的操作。通过编写VBA代码,用户可以实现复杂的业务逻辑和数据处理功能,提高工作效率。 ### 二、Python与Excel的交互 #### 1...

    ExcelCustomTaskPane:在Excel中创建基于WPF的自定义任务窗格的示例项目

    【标题】:“ExcelCustomTaskPane:在Excel中创建基于WPF的自定义任务窗格的示例项目”指的是一个利用Microsoft .NET Framework的WPF(Windows Presentation Foundation)技术,在Excel应用程序中开发自定义任务窗格...

    mac-excel

    - 将编译好的插件文件放置到Mac的Excel安装目录下的插件目录,通常是`/Library/Scripts/Applications/Microsoft Office 2016/Excel`。 6. **测试与调试**: - 在Excel中启用开发者模式,加载并测试你的插件。 - ...

    jscript之Open an Excel Spreadsheet

    - 使用`Workbooks.Open`方法打开名为`C:\Scripts\New_users.xls`的Excel文件,并将返回的工作簿对象存储在变量`objWorkbook`中。 #### 扩展知识点 - **错误处理**:在实际应用中,可能会遇到文件不存在或权限不足...

    jscript之Read an Excel Spreadsheet

    通过这个示例,我们将详细了解如何利用JScript与Microsoft Excel进行交互,包括打开工作簿、读取单元格数据以及处理这些数据的基本方法。 #### 知识点详解 ##### 1. JScript简介 JScript是Microsoft开发的一种...

    GIS-PythonScripts

    CBYD DB Builder: 该脚本获取Microsoft Exchange附件,转换为文本文件,存储所述文件,然后抓取有关“挖掘之前致电”票证的重要信息。 CBYD成分: 该脚本将从CBYD DB Builder脚本中获取Excel文件并生成点,然后将...

    a5m2_2.3.3.zip

    其次,“excel”标签揭示了A5M2与Microsoft Excel的紧密集成。Excel是一种广泛使用的电子表格程序,它的数据处理能力强大且易于理解。A5M2支持将数据库中的数据导出为Excel格式,便于分析和处理;同时,也能将Excel...

    Database.Tour.Pro.v.6.5.4.1201

    accessing different types of databases (for example, dBase, Paradox, text, CSV, Interbase, Firebird, Microsoft Access, Microsoft Excel, Oracle, SQL Server etc.); convenient viewing and editing data;...

    DbMouse Pro 5.6.3

    DbMouse is database-oriented data management console working with Microsoft SQL Server. It offers modern and effective tools for effective work with database. Although it is very simple to use, even ...

    GIS-Python-Scripts:带有GIS应用程序的Python脚本

    该脚本获取Microsoft Exchange附件,转换为文本文件,存储所述文件,然后抓取有关“挖掘之前致电”票证的重要信息。 CBYD成点: 该脚本将从CBYD DB Builder脚本中获取Excel文件并生成点,然后将点上传到ArcGIS On...

    VBA-Scripts:Visual Basic for Applications脚本的编译

    VBA(Visual Basic for Applications)是Microsoft Office套件中内置的一种编程语言,允许用户自定义功能、自动化任务和创建宏。VBA脚本是通过编写VB代码来实现这些功能的核心,它极大地提高了工作效率,尤其在处理...

    网络数据库 Query Tool

    4. 数据导入导出:工具通常具备数据导入导出功能,可以从CSV、Excel等格式导入数据,或将数据库数据导出为文件。 5. 图形化建模:高级工具可能包含数据库设计和建模功能,通过可视化方式创建和修改表结构。 SQL查询...

    简单试题库管理系统

    ASP.NET是微软公司推出的一种Web应用程序框架,它构建在.NET Framework之上,用于构建动态网站、Web应用程序和Web服务。ASP.NET的核心特性包括自动页面状态管理、事件驱动模型以及强大的服务器控件,使得开发者可以...

    Spectral Core Full Convert Enterprise v6.11.0.1683

    Easy export to Microsoft Excel Load and Save cell value Best fit columns and Auto-height rows In-place image and BLOB viewing Selected rows deletion Jump to specific record Built-in table Print ...

    SAP系统及开发技术介绍.pptx

    1. **SAP报表开发技术**:包括List(基本的输出技术)、ALV(SAP List Viewer,用于复杂界面的开发)和与Microsoft Office Excel的集成,允许数据直接导出到Excel进行处理。 2. **SAP打印技术**:SAP List/ALV可...

    access(.mdb或.asp)数据库在线管理程序汉化版.rar

    它支持SQL语言,并能与Microsoft Office其他应用如Excel无缝集成。 2. **ASP(Active Server Pages)**:ASP是微软的一种服务器端脚本环境,用于创建动态、交互式的Web应用程序。在这个案例中,ASP被用来构建Web...

    193_4ECH.PDF

    between Perl and Windows processes such as Microsoft Excel. In this chapter, I’ll also write a code component in Microsoft Visual Basic that you can connect to from Perl scripts, calling the ...

    PowerShell脚本:PowerShell脚本,范围从SCCM,MSO,AD和其他公司使用...向合作者发送猫的事实

    2. **Microsoft Office Suite (MSO)**:MSO通常指的是包括Word、Excel、PowerPoint等在内的办公应用。PowerShell可以用来自动化MSO的安装、更新和配置,例如批量修改Office设置、自动化报告生成或文件处理。 3. **...

    ConditionalAccessDocumentation:使用PowerShell的Azure AD条件访问文档

    该脚本将所有数据导出为一个csv文件,该文件可以很漂亮地格式化为excel工作簿。 从PowerShell库中安装此脚本(将自动安装相关模块): Install-Script -Name Invoke-ConditionalAccessDocumentation -Scope ...

    ComponentOne 2012 V2 ActiveReports 7(完整安装)

    ActiveReports includes Adobe PDF export with advanced encryption and international font support, Microsoft Excel export, and Rich Text Format (RTF) export. The extensive API allows fine control over ...

Global site tag (gtag.js) - Google Analytics