【问题标题】:Duplicating Excel sheet as values/pictures without references to other worksheet将 Excel 工作表复制为值/图片而不引用其他工作表
【发布时间】:2019-04-19 11:28:15
【问题描述】:

我正在尝试创建一个可以复制和重命名仪表板的宏,但不包含对其他工作表的引用。所以基本上我需要它来插入图表作为“图片”和单元格作为值。

到目前为止,我已经完成了复制,但它仍然引用其他工作表,因此相应地更改为原始仪表板。

到目前为止,这是我的代码:

Sub CopySheet()
  Dim i As Integer, x As Integer
  Dim shtname As String

  i = Application.InputBox("How many copies of this dashboard do you need?", "Copy sheet", Type:=1)
  For x = 0 To i - 1
     Worksheets("Dashboard").Copy After:=Sheets(Sheets.Count)
     shtname = InputBox("What do you want to name your new dashboard?")
     ActiveSheet.Name = shtname
 Next x
 End Sub

【问题讨论】:

    标签: excel vba charts reference copy


    【解决方案1】:

    如果我理解你的问题,你可以试试这个示例代码,你可以在其中获得 图片 作为图像和值,而无需公式:

     sub test()
        Dim sPath As String, sFile As String
        Dim wb As Workbook
    
        sPath = "yourPath\"
        sFile = sPath & "yuorFile.xlsx"
    
        Set wb = Workbooks.Open(sFile)
    
        Range("A1:B8").Select ' select my value range
        Selection.Copy 'copy it
        Windows("NameFileDestination").Activate 'destination copy value
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("yuorFile.xlsx").Activate 'active source file where there is the chart
        ActiveSheet.ChartObjects("Graphic name").Activate
        Application.CutCopyMode = False
        ActiveChart.ChartArea.Copy ' copy chart like image 
        Windows("NameFileDestination").Activate
        Range("D2").Select
        'below there is in italian immagine change in image
        ActiveSheet.PasteSpecial Format:="Immagine (PNG)", Link:=False, _
            DisplayAsIcon:=False
        ActiveWorkbook.Save
        wb.Close
    end sub
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      相关资源
      最近更新 更多