将对象粘贴到新工作簿

时间:2018-09-19 20:55:01

标签: excel vba excel-vba

我想复制表格上的一些文本框和图表,并将它们粘贴到新创建的工作簿中以生成报告。到目前为止,我一直在尝试修改在这里找到的一段代码。这是我到目前为止的内容:

Sub SampleIndividualReport()
    Dim wbI As Workbook, wbO As Workbook
    Dim wsI As Worksheet, wsO As Worksheet


    Set wbI = ThisWorkbook
    Set wsI = Sheet7

    Set wbO = Workbooks.Add

    With wbO
        Set wsO = wbO.Sheets("Sheet1")
        ActiveWindow.DisplayHeadings = False
        Application.DisplayFormulaBar = False
        ActiveWindow.DisplayGridlines = False

        .SaveAs ThisWorkbook.Path & "\" & GetSelectedSlicerItems("Slicer_Teacher") & ".xlsx"

        wsI.Range("D39:BR97").Copy

        wsO.Range("D7").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False

        wsO.Range("D7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


        wsI.Shapes.Range(Array("Chart 29", "TextBox 30")).Select
        Selection.Copy

        wsO.Range("G31").Select
        wsO.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False _
        , DisplayAsIcon:=False

        .Save

   End With
End Sub

最后一个PasteSpecial给我:运行时错误'1004':对象'_Worksheet'的方法'PasteSpecial'失败。

1 个答案:

答案 0 :(得分:0)

好的,这是从问题开始的可行解决方案

Process p = Runtime.getRuntime().exec("calc.exe");
p.waitFor();
System.out.println("Process finished");