Condividi tramite

Save a plot in Excel VBA as an image

Anonimo
2023-06-29T12:09:08+00:00

Good afternoon. I am trying to save my plot as an image in the desktop. I 've tried different methods, with no success. Could someone help me? here is the plot creation code that works. I should add only the saving part.

Sub Prova_Grafico()

'' Part 1 delete the previous plots

Dim i As Integer

For i = 1 To ActiveSheet.Shapes.Count

    ActiveSheet.Shapes(i).Delete

Next i

'' Title

Range("a12").Select

Titolo = Range("b4").Value

'' Parte 2 Plot creation

ActiveCell.CurrentRegion.Select 'Cell selection

Dim Grafico As Shape 'plot set

Set Grafico = ActiveSheet.Shapes.AddChart2(, xlXYScatter) ' Plot creation

With Grafico.Chart

    .ChartType = xlXYScatter

    .HasTitle = True

    .ChartTitle.Text = Titolo

    .ChartTitle.Font.Size = 30 ' Modify the font size as per your requirement

End With

‘Add Horizontal line

ActiveSheet.ChartObjects(Grafico.Name).Activate

ActiveChart.PlotArea.Select

ActiveChart.SeriesCollection.NewSeries

ActiveChart.FullSeriesCollection(2).Name = "=""Series 2"""

ActiveChart.FullSeriesCollection(2).XValues = "=Main!$F$58:$G$58"

ActiveChart.FullSeriesCollection(2).Values = "=Main!$F$59:$G$59"

ActiveChart.FullSeriesCollection(2).Select

With Selection.Format.Line

    .Visible = msoTrue

    .ForeColor.ObjectThemeColor = msoThemeColorAccent1

    .ForeColor.TintAndShade = 0

    .ForeColor.Brightness = 0

    .ForeColor.RGB = RGB(255, 0, 0)

End With

ActiveChart.FullSeriesCollection(2).Points(2).Select

Selection.MarkerStyle = -4142

Range("a1").Select

End Sub

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

2 risposte

Ordina per: Più utili
  1. Anonimo
    2023-06-29T12:28:55+00:00

    Traduco in italiano:
    Buonpomeriggio sto cercando di fare un codice excel vba per salvare un grafico fatto in excel VBA in immagine sul mio desktop, ma non riesco. sapreste aiutarmi?
    Questo è il codice per il grafico.
    Ringrazio e auguro una buona giornata
    mauro
    Sub Prova_Grafico()

    '' Part 1 delete the previous plots

    Dim i As Integer

    For i = 1 To ActiveSheet.Shapes.Count

        ActiveSheet.Shapes(i).Delete

    Next i

    '' Title

    Range("a12").Select

    Titolo = Range("b4").Value

    '' Parte 2 Plot creation

    ActiveCell.CurrentRegion.Select 'Cell selection

    Dim Grafico As Shape 'plot set

    Set Grafico = ActiveSheet.Shapes.AddChart2(, xlXYScatter) ' Plot creation

    With Grafico.Chart

        .ChartType = xlXYScatter

        .HasTitle = True

        .ChartTitle.Text = Titolo

        .ChartTitle.Font.Size = 30 ' Modify the font size as per your requirement

    End With

    ‘Add Horizontal line

    ActiveSheet.ChartObjects(Grafico.Name).Activate

    ActiveChart.PlotArea.Select

    ActiveChart.SeriesCollection.NewSeries

    ActiveChart.FullSeriesCollection(2).Name = "=""Series 2"""

    ActiveChart.FullSeriesCollection(2).XValues = "=Main!$F$58:$G$58"

    ActiveChart.FullSeriesCollection(2).Values = "=Main!$F$59:$G$59"

    ActiveChart.FullSeriesCollection(2).Select

    With Selection.Format.Line

        .Visible = msoTrue

        .ForeColor.ObjectThemeColor = msoThemeColorAccent1

        .ForeColor.TintAndShade = 0

        .ForeColor.Brightness = 0

        .ForeColor.RGB = RGB(255, 0, 0)

    End With

    ActiveChart.FullSeriesCollection(2).Points(2).Select

    Selection.MarkerStyle = -4142

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Gianfranco55 25,190 Punti di reputazione Moderatore volontario
    2023-06-29T12:15:27+00:00

    ciao

    gentilmente scrivete in Italiano

    questo foum è in lingua Italiana

    grazie

    La risposta è stata utile?

    0 commenti Nessun commento