VBScript Excel 行和列的复制

optionExplicit


Dim objExcel
Dim objWorkbook
Dim temp
GPTScript

Sub GPTScript
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open("E:\1.xls")
    objExcel.Visible = True

    Call CopyRowToAnother(1, 2, 30) '把第一个sheet页面中的第2行复制到第30行
    Call CopyColumnToAnother(1, 6, 30) ' 把第一个sheet页面中的第6列复制到第30列
    Call CopyColumnsRangeToAnother(6, 5, 50) '从第6列开始的五列数据复制到50列之后的五列
EndSub

Sub CopyColumnsRangeToAnother(srcStartPos,columnNum, destStartPos)
    Dim k
    For k=1To columnNum
        Call CopyColumnToAnother(1, srcStartPos+k, destStartPos+k)
    Next
EndSub

Sub CopyRowToAnother(sheetNum, row, anotherRow)
    objExcel.worksheets(sheetNum).rows(row).copy(objExcel.worksheets(sheetNum).rows(anotherRow))
EndSub

Sub CopyColumnToAnother(sheetNum, columnNum, anotherColumn)
    objExcel.Worksheets(sheetNum).Columns(columnNum).copy(objExcel.worksheets(sheetNum).Columns(anotherColumn))
EndSub


请注明文章出处:http://www.cnblogs.com/zhfuliang/

posted @ 2012-03-11 23:41  小小亮FLY  阅读(969)  评论(0编辑  收藏  举报