3

我的代码在 excel 2007 中运行得非常好,但在 excel 2003 中没有运行。它给出“编译错误”并且这条线变成红色。

 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
4

1 回答 1

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
于 2013-03-01T00:41:12.650 回答