VBA - 如何将范围导出到图像 - MAC

时间:2018-06-10 09:22:16

标签: excel vba image macos export

我正在尝试在Mac(High Sierra)中将Excel 2016(16.13)中的一系列单元格导出为图像。

到目前为止,这是我设法组合起来的......

Sub Export() 

Dim oWs As Worksheet
Dim oRng As Range
Dim oChrtO As ChartObject
Dim lWidth As Long, lHeight As Long
'
Set oWs = ActiveSheet
Set oRng = oWs.Range("C8:I20")
'
oRng.CopyPicture xlScreen, xlPicture
lWidth = oRng.Width
lHeight = oRng.Height
'
Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
'
oChrtO.Activate
With oChrtO
.ShapeRange.Line.Visible = msoFalse
.Height = oRng.Height
.Width = oRng.Width
.Chart.Paste
.Chart.Export FileName:="Report.png", Filtername:="JPG"
End With
'
oChrtO.Delete
'
End Sub

我仍然有以下问题:

1 - 自动文件保存到/Users/MyAccount/Library/Containers/com.microsoft.Excel/Data/中,我需要将其保存到桌面上的特定文件夹中

2-“小化妆品问题”,左边和上边缘是灰色的(file.png) - enter image description here

有任何建议吗?

编辑: 我还尝试添加:

Dim fileAccessGranted As Boolean
Dim filePermissionCandidates
'Create an array with file paths for which permissions are needed
filePermissionCandidates = Array("/Users/<MyAccount>/Desktop/")
'Request Access from User
fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)

.Chart.Export FileName:="/Users/<MyAccount>/Desktop/Case.jpg", Filtername:="JPG"

导致错误“运行时错误'70'权限被拒绝”。

0 个答案:

没有答案