Create an Excel file using vbscripts

前端 未结 5 1395
清歌不尽
清歌不尽 2020-12-29 12:36

How do I create an excel file using VBScript? I searched the net but it just mentions opening an existing file.

This is the extraction from the Internet

5条回答
  •  无人及你
    2020-12-29 13:18

    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = true
    Set objWorkbook = objExcel.Workbooks.Add()
    Set objWorksheet = objWorkbook.Worksheets(1)
    
    intRow = 2
    dim ch
    objWorksheet.Cells(1,1) = "Name"
    objWorksheet.Cells(1,2) = "Subject1"
    objWorksheet.Cells(1,3) = "Subject2"
    objWorksheet.Cells(1,4) = "Total"
    for intRow = 2 to  10000 
    name= InputBox("Enter your name")
    sb1 = cint(InputBox("Enter your Marks in Subject 1"))
    sb2 = cint(InputBox("Enter your Marks in Subject 2"))
    total= sb1+sb2+sb3+sb4
    objExcel.Cells(intRow, 1).Value = name
    objExcel.Cells(intRow, 2).Value = sb1
    objExcel.Cells(intRow, 3).Value = sb2
    objExcel.Cells(intRow, 4).Value = total
    ch = InputBox("Do you want continue..? if no then type no or y to continue")
        If ch = "no" Then Exit For 
    Next
    
    objExcel.Cells.EntireColumn.AutoFit
    
    MsgBox "Done"
    enter code here
    

提交回复
热议问题