Advertisement
YasserKhalil2019

T4122_Export Range To Image With High Quality

Oct 13th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. https://excel-egy.com/forum/t4122
  2. ---------------------------------
  3.  
  4. Sub Test_ExportRangeToImage()
  5. Dim c As Range, r As Range, p As String
  6.  
  7. Set c = ActiveCell
  8. Set r = Worksheets(1).Range("D5:K20")
  9. p = ThisWorkbook.Path & "\" & Worksheets(1).Range("G1").Value & "_" & format(Date, "yyyy.mm.dd") & ".png"
  10.  
  11. ExportRangeToImage r, p
  12. Application.Goto c
  13. End Sub
  14.  
  15. Sub ExportRangeToImage(oRng As Range, fName As String)
  16. oRng.CopyPicture xlScreen, xlPicture
  17. Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Temp"
  18.  
  19. With ActiveSheet
  20. .Shapes.AddChart.Select
  21. .Shapes("Chart 1").Width = oRng.Width
  22. .Shapes("Chart 1").Height = oRng.Height
  23. ActiveChart.Paste
  24. .Shapes("Chart 1").ScaleWidth 2, msoFalse, msoScaleFromTopLeft
  25. .Shapes("Chart 1").ScaleHeight 2, msoFalse, msoScaleFromTopLeft
  26. ActiveChart.Export fileName:=fName, filtername:="png"
  27. End With
  28.  
  29. Application.DisplayAlerts = False
  30. Sheets("Temp").Delete
  31. Application.DisplayAlerts = True
  32. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement