控制导出图表的分辨率
Control resolution of exported chart
我有一个 excel 用户窗体,它允许您将特定工作表中的 excel 图表保存为 .jpg 图像,同时在用户窗体中显示图表。但是我发现很难控制所述图像的分辨率。分辨率似乎取决于工作表上的缩放量。当我放大时,我得到了高质量的图像,而当我缩小时,分辨率变得很差。有没有办法使用 vba 代码来控制它?
我用于导出的代码如下:
Private Sub CmdBrowse_Click()
Dim Directory1 As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
Directory1 = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
ChartDest.Value = Directory1
End Sub
Private Sub CmdLoad_Click()
Dim FilePath As String
Dim Imagename As String
Dim ChartNumber As Integer
If ChartDest = "Select chart destination folder" Then
MsgBox "Select chart destination"
Exit Sub
End If
ChartNumber = ChartList.ListIndex + 1
'saving chart to image
Imagename = ChartList.Value
FilePath = ChartDest & Imagename & ".jpeg"
ThisWorkbook.Worksheets("Blad3").ChartObjects(ChartNumber).Chart.Export FilePath, "jpg"
'loading image
UserForm4.ChartImage.Picture = LoadPicture(FilePath)
End Sub
ChartDest 是带有目标路径的文本框。
Chartlist 是一个包含可用图表列表的列表框
在你的 CmdLoad 中试试这个
Private Sub CmdLoad_Click()
Dim fPath As String, imgName As String, chartID As Long
If chartDest = "Select chart destination folder" Then
MsgBox "Select chart destination"
Exit Sub
End If
chartID = ChartList.ListIndex + 1
'saving chart to image
imgName = ChartList.Value
fPath = chartDest & imgName & ".jpeg"
With ThisWorkbook.Worksheets("Blad3").ChartObjects(chartID)
ActiveWindow.Zoom = 175
.Chart.Export fPath, "jpg"
ActiveWindow.Zoom = 100
End With
'loading image
UserForm4.ChartImage.Picture = LoadPicture(fPath)
End Sub
我有一个 excel 用户窗体,它允许您将特定工作表中的 excel 图表保存为 .jpg 图像,同时在用户窗体中显示图表。但是我发现很难控制所述图像的分辨率。分辨率似乎取决于工作表上的缩放量。当我放大时,我得到了高质量的图像,而当我缩小时,分辨率变得很差。有没有办法使用 vba 代码来控制它?
我用于导出的代码如下:
Private Sub CmdBrowse_Click()
Dim Directory1 As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
Directory1 = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
ChartDest.Value = Directory1
End Sub
Private Sub CmdLoad_Click()
Dim FilePath As String
Dim Imagename As String
Dim ChartNumber As Integer
If ChartDest = "Select chart destination folder" Then
MsgBox "Select chart destination"
Exit Sub
End If
ChartNumber = ChartList.ListIndex + 1
'saving chart to image
Imagename = ChartList.Value
FilePath = ChartDest & Imagename & ".jpeg"
ThisWorkbook.Worksheets("Blad3").ChartObjects(ChartNumber).Chart.Export FilePath, "jpg"
'loading image
UserForm4.ChartImage.Picture = LoadPicture(FilePath)
End Sub
ChartDest 是带有目标路径的文本框。 Chartlist 是一个包含可用图表列表的列表框
在你的 CmdLoad 中试试这个
Private Sub CmdLoad_Click()
Dim fPath As String, imgName As String, chartID As Long
If chartDest = "Select chart destination folder" Then
MsgBox "Select chart destination"
Exit Sub
End If
chartID = ChartList.ListIndex + 1
'saving chart to image
imgName = ChartList.Value
fPath = chartDest & imgName & ".jpeg"
With ThisWorkbook.Worksheets("Blad3").ChartObjects(chartID)
ActiveWindow.Zoom = 175
.Chart.Export fPath, "jpg"
ActiveWindow.Zoom = 100
End With
'loading image
UserForm4.ChartImage.Picture = LoadPicture(fPath)
End Sub