Open operation excel, word

Set excelApp = CreateObject("excel.Application")
excelApp.Visible = true
excelApp.Workbooks.Open "d:\1.xls"
Set osheet = excelApp.Sheets.Item(1) 'Rename sheet
osheet.Name = "hello"
osheet.Cells(1,1) = "test123" 'Enter data in the first row and first column
excelApp.ActiveWorkbook.Save
Set excelApp = nothing

 In this way of operating excle, you can customize a test report later

 

Excel.Application objects can also be created to operate on Excel files.

Set ExcelApp=CreateObject("Excel.Application") ' Create an ExcelApp object

Set ExcelWor=ExcelApp.Workbooks.Open("C:/Users/luyime/Desktop/another.xls") ' Open the excel file workbook

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange 'UsedRange is needed here , which means the range of cells used by Sheet1 , otherwise all cells will be printed out

rowcount=ExcelShe.Rows.count ' Calculate the number of cell rows used

columncount=ExcelShe.Columns.count ' Calculate the number of columns of cells used

For i=1 to rowcount

                      For j=1 to columncount

                                                      Msgbox ExcelShe.Cells(i,j) ' Print out the contents of the cells

                      Next     

Next

Set ExcelShe=Nothing

ExcelWor.Close ' Close the workbook object

ExcelApp.Quit ' Quit the ExcelApp object

The above mainly uses some properties and methods of the WorkSheet object, such as UsedRange, Cells, Rows, Columns , etc.

 

 

The following is the operation word

Set wobj = CreateObject(”Word.Application”)
wobj.Visible = True
Set Doc = wobj.Documents.Add
Set Range = Doc.Paragraphs.Add.Range
Range.Text = “The first Paragraph”
Doc.Paragraphs.Add
Set Range2 = Doc.Paragraphs.Add.Range
Range2.Text = “The second Paragraph”
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326443481&siteId=291194637