Duplicating Excel sheet as values/pictures without references to other worksheet

Viewed 117

I am trying to create a macro that dublicates and renames a dashboard, but doesn't include references to other worksheets. So basically i need it to insert charts as "pictures" and cells as values.

Until now, I have finished the duplication, but it still refers back to other worksheets and hence change correspondingly to the original dashboard.

Here is my code so far:

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
1 Answers

if i understood your question you can try this example code where you get an picture as image and value without formula:

 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

Hope this helps

Related