Happy Monday Excellers, welcome back to the next blog post in my 2019 #macromonday series. Today let’s write a quick and easy Excel VBA macro to save an Excel chart as an image file. So, this macro is useful if you copy and paste, or use the snipping tool. Or if you use some other method to copy your Excel charts.
Preparing To Write The Macro
First, you will need to open the Visual Basic Editor. There are two ways to do this. Either by hitting ALT +F11 or selecting the Developer Tab | Code Group | Visual Basic. Both methods have the same result. You then have a choice, you can either create a module to store your code either in your Personal Macro Workbook or in your current workbook. What’s the difference?. If you save the macro in your Personal Macro workbook it will be available for use in any of my Excel workbooks. If you store it in the current workbook then use is restricted to that workbook.
In this example I want to store this macro in my Personal Macro workbook.
Learn More About Your Personal Macro Workbook (PMW)
If you want to read more about your Excel PMW then check out my blog posts below.
Macro Mondays -Creating and Updating Your Personal Macro Workbook
Why Is My Personal Macro Workbook Not Loading Automatically?
Macro Mondays – Create A Shortcut To Your Personal Excel Macro Workbook
Starting The Macro
We need to start off the macro by inserting a New Module. Do this by selecting the Personal.
[stextbox id=’info’]
Sub ChartExport()
End Sub
[/stextbox]
Use The Chart.Export Method
The Chart
[stextbox id=’info’]
ActiveChart.Export
[/stextbox]
The parameters for this method include
Filename (a string). This is the name of the exported file. This is a required parameter. In this example, I have decided to name the default name of the active chart. The full file path is the default active workbook file path. It has the PNG extension.
FilterName (Object). This is the language-independent name of the graphics filter as it appears in the registry. This is an optional parameter. In this example it is PNG.
[stextbox id=’info’]
Filename:=ActiveWorkbook.path & “\” & ActiveChart.Name & “.png”, FilterName:=”PNG”
[/stextbox]
F
Ending The Macro
Once the chart has exported, the code finally ends with the End Sub piece of code. This was already entered into the module for us when started the type the name of the macro.
[stextbox id=’info’]
End Sub
[/stextbox]
More Related #MacroMonday Blog Posts
Write A Macro To Copy Filtered Rows To A New Excel Workbook
VBA Sub and Function Procedures- Explanation and Examples – Macro Monday
If you want more tips then sign up to my monthly Newsletter where I share 3 Excel Tips on the first Wednesday of the month and receive my free Ebook, 30 Excel Tips.
More Related #MacroMonday Blog Posts
Write A Macro To Copy Filtered Rows To A New Excel Workbook
VBA Sub and Function Procedures- Explanation and Examples – Macro Monday
If you want more tips then sign up to my monthly Newsletter where I share 3 Excel Tips on the first Wednesday of the month and receive my free Ebook, 30 Excel Tips.
Likewise, if you want to see all of the blog posts in the Macro Mondays Series Click The Link Below