Sub ExportChart() Const sSlash$ = "/" Const sPicType$ = ".gif" Dim sChartName$ Dim sPath$ Dim sBook$ Dim objChart As ChartObject On Error Resume Next Set objChart = ActiveSheet.ChartObjects(1) If objChart Is Nothing Then MsgBox "No charts have been detected on this sheet", 0 Exit Sub End If If ActiveChart Is Nothing Then MsgBox "You must select a single chart for exporting ", 0 Exit Sub End If Start: sChartName = Application.InputBox("Please Specify a name for the exported chart" & vbCr & _ "There is no default name available" & vbCr & _ "The chart will be saved in the same folder as this file", "Chart Export", "") If sChartName = Empty Then MsgBox "You have not entered a name for this chart", , "Invalid Entry" GoTo Start End If If sChartName = "False" Then Exit Sub End If sBook = ActiveWorkbook.Path sPath = sBook & sSlash & sChartName & sPicType ActiveChart.Export Filename:=sPath, FilterName:="GIF" End Sub
Private Sub Cambia_Grafico() Dim Grafico As Chart Dim sh As Worksheet Set sh = ThisWorkbook.Sheets("Grafici") sh.Shapes(Me.ComboBox1.Value).Select '<----------------------- Riga aggiunta Set Grafico = sh.Shapes(Me.ComboBox1.Value).Chart Grafico.Export VBA.Environ("TEMP") & Application.PathSeparator & "Grafico.jpg" Me.Image1.Picture = LoadPicture(VBA.Environ("TEMP") & Application.PathSeparator & "Grafico.jpg") End Sub
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("I3")) Is Nothing Then Select Case Target Case "tutti" cht = 1 Case "serie1" cht = 2 Case "serie2" cht = 3 Case "serie3" cht = 4 Case "serie4" cht = 5 Case "serie5" cht = 6 End Select With ActiveSheet For i = 1 To 6 .ChartObjects(i).Visible = False Next i .ChartObjects(cht).Visible = True End With End If End Sub
Private Sub Cambia_Chart() Dim sh As String, cht As String, grf As String Dim percorso On Error Resume Next 'elimina il grafico precedente, se esiste Kill ActiveWorkbook.Path & "\" & "Grafico*" & ".gif" On Error GoTo 0 sh = "Grafici" cht = ComboBox1.Value grf = "Grafico" percorso = ActiveWorkbook.Path & "\" & grf & ".gif" ActiveSheet.ChartObjects(cht).Activate ActiveChart.Export Filename:=percorso, Filtername:="GIF" Me.Image1.Picture = LoadPicture(percorso) End Sub