我有一个excel userform,它允许您将特定工作表中的Excel图表保存为.jpg图像,同时在userform中显示图表。但是我发现很难控制所述图像的分辨率。分辨率似乎取决于工作表上的缩放量。当我放大时,我得到一个高质量的图像,当我缩小时,分辨率变得非常差。有没有办法使用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是一个包含可用图表列表的列表框
答案 0 :(得分:3)
在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