This copy, save method worked for me,. I put it in 3 sections (declarations, saves it as an EMF function and a section for selecting / copying / calling functions):
* I found in this article , which describes in detail how to save to EMF, and then learned a little how to use ActiveChart instead of arbitrary selection.
First do a couple of declarations:
Option Explicit Private Declare Function OpenClipboard _ Lib "user32" ( _ ByVal hwnd As Long) _ As Long Private Declare Function CloseClipboard Lib "user32" () As Long Private Declare Function GetClipboardData _ Lib "user32" ( _ ByVal wFormat As Long) _ As Long Private Declare Function EmptyClipboard Lib "user32" () As Long '// CreateMetaFileA DeleteEnhMetaFile Private Declare Function CopyEnhMetaFileA _ Lib "gdi32" ( _ ByVal hENHSrc As Long, _ ByVal lpszFile As String) _ As Long Private Declare Function DeleteEnhMetaFile _ Lib "gdi32" ( _ ByVal hemf As Long) _ As Long
This is the actual save as an emf function (using CopyEnhMetaFileA and DeleteEnhMetaFile is explained in the article):
Public Function fnSaveAsEMF(strFileName As String) As Boolean Const CF_ENHMETAFILE As Long = 14 Dim ReturnValue As Long OpenClipboard 0 ReturnValue = CopyEnhMetaFileA(GetClipboardData(CF_ENHMETAFILE), strFileName) EmptyClipboard CloseClipboard '// Release resources to it eg You can now delete it if required '
Then the section for selecting, copying and calling functions:
Sub SaveIt() Charts.Add ActiveChart.ChartArea.Select Selection.Copy If fnSaveAsEMF("C:\Excel001.emf") Then MsgBox "Saved", vbInformation Else MsgBox "NOT Saved!", vbCritical End If End Sub
source share