Provato su Excel 2007 ma dovrebbe funzionare su tutte le versioni.
Se volete esportare un grafico direttamente da excel potete utilizzare questo script VBA che ho originariamente trovato su http://peltiertech.com . Purtroppo la versione descritta in quel sito non funzionava. Questa è la versione corretta.
Sub ExportChart()
Dim sChartName As String
Dim sPrompt As String
Dim sDefault As String
If ActiveSheet Is Nothing Then GoTo ExitSub
If ActiveChart Is Nothing Then GoTo ExitSub
sPrompt = "Chart will be exported into directory of active workbook."
sPrompt = sPrompt & vbNewLine & vbNewLine
sPrompt = sPrompt & "Enter a file name for the chart, "
sPrompt = sPrompt & "including an image file extension (e.g., .png, .gif)."
sDefault = ""
Do
sChartName = Application.InputBox(sPrompt, "Export Chart", sDefault, , , , , 2)
If Len(sChartName) = 0 Then GoTo ExitSub
If sChartName = "False" Then GoTo ExitSub
Select Case True
Case UCase$(Right(sChartName, 4)) = ".PNG"
Case UCase$(Right(sChartName, 4)) = ".GIF"
Case UCase$(Right(sChartName, 4)) = ".JPG"
Case UCase$(Right(sChartName, 4)) = ".JPE"
Case UCase$(Right(sChartName, 5)) = ".JPEG"
Case Else
sChartName = sChartName & ".png"
End Select
If (ActiveWorkbook.Path & "\" & sChartName) <> "" Then Exit Do
sPrompt = "A file named '" & sChartName & "' already exists."
sPrompt = sPrompt & vbNewLine & vbNewLine
sPrompt = sPrompt & "Select a unique file name, "
sPrompt = sPrompt & "including an image file extension (e.g., .png, .gif)."
sDefault = sChartName
Loop
ActiveChart.Export ActiveWorkbook.Path & "\" & sChartName
ExitSub:
End Sub |
Sub ExportChart()
Dim sChartName As String
Dim sPrompt As String
Dim sDefault As String
If ActiveSheet Is Nothing Then GoTo ExitSub
If ActiveChart Is Nothing Then GoTo ExitSub
sPrompt = "Chart will be exported into directory of active workbook."
sPrompt = sPrompt & vbNewLine & vbNewLine
sPrompt = sPrompt & "Enter a file name for the chart, "
sPrompt = sPrompt & "including an image file extension (e.g., .png, .gif)."
sDefault = ""
Do
sChartName = Application.InputBox(sPrompt, "Export Chart", sDefault, , , , , 2)
If Len(sChartName) = 0 Then GoTo ExitSub
If sChartName = "False" Then GoTo ExitSub
Select Case True
Case UCase$(Right(sChartName, 4)) = ".PNG"
Case UCase$(Right(sChartName, 4)) = ".GIF"
Case UCase$(Right(sChartName, 4)) = ".JPG"
Case UCase$(Right(sChartName, 4)) = ".JPE"
Case UCase$(Right(sChartName, 5)) = ".JPEG"
Case Else
sChartName = sChartName & ".png"
End Select
If (ActiveWorkbook.Path & "\" & sChartName) <> "" Then Exit Do
sPrompt = "A file named '" & sChartName & "' already exists."
sPrompt = sPrompt & vbNewLine & vbNewLine
sPrompt = sPrompt & "Select a unique file name, "
sPrompt = sPrompt & "including an image file extension (e.g., .png, .gif)."
sDefault = sChartName
Loop
ActiveChart.Export ActiveWorkbook.Path & "\" & sChartName
ExitSub:
End Sub
Una volta che avete associato questa macro ad una combinazione di tasti tipo “CTRL+E” un popup vi chiederà di con che nome volete salvare il file e con che estensione. Il file verrà salvato nella stessa cartella del file excel.
Nessun commento presente