Using VBScript to manipulate sample code for Excel

Source: Internet
Author: User
Tags first row

We can use VBScript to quickly batch some Excel files. The VBScript script needs to be saved as a. vbs file, which is very convenient to run by double-clicking.

The following is sample code, save as a Run.vbs file:

' On Error Resume Next

' Define params:

Im Excelapp

Im Objworkbook

Im Objimportsheet

Im path

Path = "C:/users/administrator/desktop"

' Open Excel:

' From

Set Excelapp = CreateObject ("Excel.Application")

Excelapp.visible = False

Set Objworkbook = ExcelApp.Workbooks.Open (Path & "/1.xls")

Set Xlssheet = objworkbook.sheets ("Sheet1") ' page number is called

' Read datas:

MsgBox "First Row first column value:" & Xlssheet.cells (1,1). Value

MsgBox "The second row of the first column value:" & Xlssheet.cells (2,1). Value

MsgBox "Second row of second column value:" & Xlssheet.cells (2,2). Value

' Set cells Data:

Xlssheet.cells (3,1). value= "inserted data ..."

MsgBox "The third row of the first column value:" & Xlssheet.cells (3,1). Value

' Save

Objworkbook.saveas Path & "/new.xls"


' Close


' Clean & Quit:


Set Objworkbook = Nothing

Set Objimportsheet = Nothing

Set excelapp = Nothing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.