2012-01-18 6 views

答えて

1

This articleは、VBAを使用してExcelチャートをイメージとしてエクスポートする方法を説明しています。

+0

イメージを作成しようとしている他の誰のためだけ注記:

これはあなたを助けるかもしれないVBAコードです。 Excel 2010を使用している場合は、グラフをアクティブにしてからイメージとしてエクスポートする必要があります(oChart.Activate)。 – nickfinity

+0

チャートをアクティブにする必要はありません。 Exportメソッドはチャートオブジェクトではなく、チャートと一緒に実行されます(これは、何らかの作業を行うためにチャートをアクティブにする必要があることを発見したときに共通の問題です)。 –

0

私のプロジェクトで同様のことをする必要がありました。これはチャートをアプリケーションからライブデータを実行するダッシュボードに変換することでした。 私のソリューションは、ODBCを介してアプリケーションのデータベースに接続することで終わったとリバースエンジニアリングのチャート(レポート)の生成をVBA

ステップとステップによって:

1. do an automatic refresh of data by setting a refresh interval in the Excel Data Query 
2. extract the information from the Excel worksheet with VBA 
3. generate Pivot Tables and Pivot Charts upon the information extracted with VBA 
4. convert the Pivot Charts or Range of Cells(=Tables) to Images and Paste them above the Chart Objects in the Excel Worksheets 
5. cut area(s) from the Worksheets (that contained the chart or tables) by giving dimensions and save these as images 
6. read the images saved at the previous stage via a webpage (depending on its additional content either static-.html or dynamic 
.aspx) 
7. set a refreshment time in the webpage source, and there is the dashboard 

あなたは上記お気づきのように、私がやりましたチャートをイメージに変換するのではなく、チャートをイメージに含むワークシートの領域を変換します。

Sub Pivot_Chart_And_Table_of_Auftragsart_To_Image() 
'the code for selecting successively the areas of Pivot Table and Pivot Chart and save them as image file types .jpg to a defined directory path 

'below you set the Range(=Area in the Worksheet) you want to export to file 
Dim rgExp As Range 

Set rgExp = Range("A1:E5") 

''' Copy range as picture onto Clipboard 
rgExp.CopyPicture Appearance:=xlScreen, Format:=xlBitmap 
''' Create an empty chart with exact size of range copied 
With ActiveSheet.ChartObjects.Add(Left:=rgExp.Left, Top:=rgExp.Top, _ 
Width:=rgExp.Width, Height:=rgExp.Height) 
.Name = "nameOfTheObjectHerewithGenerated" 
.Border.LineStyle = xlNone 'this removes the border line of the temporary Chart Object 
.Activate 
End With 

''' Paste into chart area, export to file 
ActiveChart.Paste 

ActiveSheet.ChartObjects("nameOfTheObjectHerewithGenerated").Chart.Export "C:\whateverDirectoryYouWish\nameOfImage.jpg" 
関連する問題