【发布时间】:2021-06-19 01:37:13
【问题描述】:
我发现该帖子正在调查,但不幸的是没有回答我想到的问题 如何将 EXCEL 中的图形导出为 *.EMF
Excel export chart to wmf or emf?
提供的代码对我不起作用。 我所做的是像“Private Declare PtrSafe Function”一样扩展每个“Private Declare Function”,使其适用于64BIT。
代码:
Option Explicit
Private Declare PtrSafe Function OpenClipboard _
Lib "user32" ( _
ByVal hwnd As Long) _
As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Private Declare PtrSafe Function GetClipboardData _
Lib "user32" ( _
ByVal wFormat As Long) _
As Long
Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
'// CreateMetaFileA DeleteEnhMetaFile
Private Declare PtrSafe Function CopyEnhMetaFileA _
Lib "gdi32" ( _
ByVal hENHSrc As Long, _
ByVal lpszFile As String) _
As Long
Private Declare PtrSafe Function DeleteEnhMetaFile _
Lib "gdi32" ( _
ByVal hemf As Long) _
As Long
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
'// or write over it. This is a MUST
DeleteEnhMetaFile ReturnValue
fnSaveAsEMF = (ReturnValue <> 0)
End Function
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
我想使用此代码将带有工作表名称的工作表中的图形自动导出到循环内的特定文件夹中,以防万一。如果可以通过按钮执行,则突出显示。
到目前为止,当我运行代码时,我得到的只是一条“未保存”消息。我正在使用 Excel 365 ProPlus,以防万一。
如果有人能解释一下这段代码是如何工作的以及我需要在那里实现什么,我将不胜感激
【问题讨论】:
-
@BigBen:我附上了我使用的 vba 代码。
标签: excel vba vector-graphics