I am sharing here yet another great Excel technique from Rob van Gelder. This procedure allows you to click a chart in any open workbook and run the macro to convert the chart to a .emf file at the location of your choice. See:
http://dailydoseofexcel.com/archives/2012/05/05/copy-chart-as-a-picture/#comments
The code from that article is shown here.
Declare Function OpenClipboard Lib “user32” (ByVal hwnd As Long) As Long
Declare Function CloseClipboard Lib “user32” () As Long
Declare Function GetClipboardData Lib “user32” (ByVal wFormat As Long) As Long
Declare Function EmptyClipboard Lib “user32” () As Long
Declare Function CopyEnhMetaFileA Lib “gdi32” (ByVal hENHSrc As Long, ByVal lpszFile As String) As Long
Declare Function DeleteEnhMetaFile Lib “gdi32” (ByVal hemf As Long) As Long
Const CF_ENHMETAFILE As Long = 14
Const cInitialFilename = “Picture1.emf”
Const cFileFilter = “Enhanced Windows Metafile (*.emf), *.emf”
Public Sub SaveAsEMF()
Dim var As Variant, lng As Long
var = Application.GetSaveAsFilename(cInitialFilename, cFileFilter)
If VarType(var) <> vbBoolean Then
On Error Resume Next
Selection.Copy
OpenClipboard 0
lng = GetClipboardData(CF_ENHMETAFILE)
lng = CopyEnhMetaFileA(lng, var)
EmptyClipboard
CloseClipboard
DeleteEnhMetaFile lng
On Error GoTo 0
End If
End Sub
You can download the file containing this procedure here.
Important note: This solution will run correctly only on 32-bit systems – not 64-bit. If you really need it to work on 64-bit, you can try to modify the code based on the information located at:
Pingback: #Excel Super Links #43 – shared by David Hager | Excel For You
Pingback: #Excel Super Links #44 – shared by David Hager | Excel For You
Pingback: #Excel For You Blog Posts Having Downloadable Workbook Files by David Hager | Excel For You
Pingback: #Excel Super Links #150 – Special Edition | Excel For You