'Excel VBA to copy range as picture and save on path for MACOS
Hello i have made a excel vba code which copy range (A1:O25) as picture and then paste it on a path as JPG. path is written in R1 cell every time code will get the path from R1 but problem is that the module is correctly working on windows but it is not working on MACOS it gives an error "Error 70 at runtime: Consent denied" What is the solution of this?
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("A1:O25")
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
Dim pathaddress As String
pathaddress = Range("R1").Value
With oChrtO
.ShapeRange.Line.Visible = msoFalse
.Height = oRng.Height
.Width = oRng.Width
.Chart.Paste
.Chart.Export pathaddress & oChrtO.name & ".jpg"
End With
oChrtO.Delete
End Sub
enter code here
Solution 1:[1]
*check pathaddress = E:\data*
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("A1:O25")
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
Dim pathaddress As String
pathaddress = Range("R1").text
With oChrtO
.ShapeRange.Line.Visible = msoFalse
.Height = oRng.Height
.Width = oRng.Width
.Chart.Paste
.Chart.Export pathaddress & oChrtO.name & ".jpg"
End With
oChrtO.Delete
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jahanzaib Sehar |
