我正在尝试创建一个宏,该宏可以复制仪表板并将其重命名,但是不包含对其他工作表的引用。所以基本上我需要它来插入图表作为“图片”和单元格作为值。
到现在为止,我已经完成了重复,但是它仍然指向其他工作表,因此相应地更改为原始仪表板。
到目前为止,这是我的代码:
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
答案 0 :(得分:0)
如果我理解了您的问题,可以尝试使用以下示例代码,在其中获得图片作为图像和没有公式的值:
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
希望这会有所帮助