Excel 2003中的代码错误

时间:2013-02-28 22:40:49

标签: excel vba excel-vba excel-2003

我有一个代码在excel 2007上运行得非常好,但它没有运行excel 2003.它给出了“complie错误”,这一行变为红色。

 Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _

您的建议会有很大帮助。谢谢。如果您需要我方提供的任何信息,请通知我。

这是我的完整代码:

'-------------------------------------
' Create Final Report
'-------------------------------------
Sub FinalReport()
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
Dim btn, rght As Long
Dim NewWbk As String

NewWbk = "Final_Report"

' Add a new workbook
    Application.Workbooks.Add
    Range("A1").Select
' Rename the workbook
    ActiveWorkbook.SaveAs Filename:=thisWb.Path & Application.PathSeparator & "Final_Report" & ".xls"

    Windows("Tool_01082013.xls").Activate
    Sheets("Reports").Activate

' select the sheet and range to be copied
Range("B2:AO34").Select

' Copy the selected range...
    Selection.Copy
    Workbooks("Final_Report.xls").Sheets("Sheet1").Activate

' and Paste it into the new workbook
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False

Windows("Tool_01082013.xls").Activate
    Sheets("Reports_Month").Activate

' select the sheet and range to be copied
Range("A1:DR34").Select

' Copy the selected range...
    Selection.Copy
    Workbooks("Final_Report.xls").Sheets("Sheet2").Activate

' and Paste it into the new workbook
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
Workbooks("Final_Report.xls").Save
Workbooks("Final_Report.xls").Close
Windows("Tool_01082013.xls").Activate
    With Sheets("Reports")
        .Activate
        .Range("A5").Select  '-- move focus to the first item
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

试试这个:

'-------------------------------------
' Create Final Report
'-------------------------------------
Sub FinalReport()

    Dim thisWb As Workbook, _
        finalReport as Workbook, _
        toolWB as Workbook
    Set thisWb = ActiveWorkbook
    Dim copyrange As Range

    ' Add a new workbook
    set finalReport = Application.Workbooks.Add
    ' Rename the workbook
    finalReport.SaveAs Filename:=thisWb.Path & Application.PathSeparator & "Final_Report.xls"

    set toolWB = Workbooks("Tool_01082013.xls")
    Set copyrange = toolWB.Sheets("Reports").Range("B2:AO34")
    finalReport.Sheets("Sheet1").Range("A1").Resize(copyrange.Rows.Count, copyrange.Columns.Count).Value = copyrange.Value
    Set copyrange = toolWB.Sheets("Reports_Month").Range("A1:DR34")
    finalReport.Sheets("Sheet2").Range("A1").Resize(copyrange.Rows.Count, copyrange.Columns.Count).Value = copyrange.Value

    finalReport.Save
    finalReport.Close
    Application.Goto toolWB.Sheets("Reports").Range("A5")

End Sub