2011年計算機等級二級VB輔導知識技巧總結(26)(5)

字號:


    Set xlTagBook = xlCopyApp.Workbooks.Open(strTagWorkbook)
    End If
    Set ExcelSource = xlSrcBook.Worksheets(strSrcSheetName)
    Set ExcelTarget = xlTagBook.Worksheets(strTagSheetName)
    ExcelSource.Select
    ExcelSource.Cells.Copy
    ExcelTarget.Select
    ExcelTarget.Paste
    xlCopyApp.Application.CutCopyMode = xlCopy
    If strSrcWorkBook = strTagWorkbook Then
    xlTagBook.Save
    xlSrcBook.Save
    Else
    xlTagBook.Save
    End If
    Set ExcelSource = Nothing
    Set ExcelTarget = Nothing
    Set xlSrcBook = Nothing
    Set xlTagBook = Nothing
    CopySheet = True
    End If
    End Function
    ‘復制工作表
    Function ExcelCopySheet(ByVal strSrcSheetName As String, ByVal strSrcWorkBook As String, ByVal strTagSheetName As String, ByVal strTagWorkbook As String, xlCopyApp As Excel.Application) As Boolean
    Dim xlSrcBook As Excel.Workbook
    Dim xlTagBook As Excel.Workbook
    Dim ExcelSource As Excel.Worksheet
    Dim ExcelTarget As Excel.Worksheet
    Dim Result As Boolean
    If CheckFile(strSrcWorkBook) = False Or CheckFile(strTagWorkbook) = False Then
    Set ExcelSource = Nothing
    Set ExcelTarget = Nothing
    Set xlSrcBook = Nothing
    Set xlTagBook = Nothing
    CopySheet = False
    Exit Function
    Else