Pepito_child
New Member
- Joined
- Feb 13, 2016
- Messages
- 49
Hello dear experts,
I kindly ask for your support!
How should the bellow export file code be changed with a different path, instead of "Desktop" to this new path from server: X:\Production\PLAN?
Is there any idea of how it could also have a warning message when it will already exist a similar file name in this new path - e.g. replace or skip files "The destination already has a file named "xxxxx.png"?
Thank you and I appreciate your hard work here!
Sub ExportImage()
Dim sFilePath As String
Dim sView As String
sView = ActiveWindow.View
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = False
Set Sheet = ActiveSheet
sFilePath = CreateObject("WScript.Shell").specialfolders("Desktop") & "\" & Range("M2") & ".png"
zoom_coef = 300 / Sheet.Parent.Windows(1).Zoom
Set area = Sheet.Range("M1:X27")
area.CopyPicture xlPrinter
Set chartobj = Sheet.ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Activate
chartobj.Chart.Paste
chartobj.Chart.Export sFilePath, "png"
chartobj.Delete
ActiveWindow.View = sView
Application.ScreenUpdating = True
MsgBox ("Export completed! The file can be found here:" & Chr(10) & Chr(10) & sFilePath)
End Sub
I kindly ask for your support!
How should the bellow export file code be changed with a different path, instead of "Desktop" to this new path from server: X:\Production\PLAN?
Is there any idea of how it could also have a warning message when it will already exist a similar file name in this new path - e.g. replace or skip files "The destination already has a file named "xxxxx.png"?
Thank you and I appreciate your hard work here!
Sub ExportImage()
Dim sFilePath As String
Dim sView As String
sView = ActiveWindow.View
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = False
Set Sheet = ActiveSheet
sFilePath = CreateObject("WScript.Shell").specialfolders("Desktop") & "\" & Range("M2") & ".png"
zoom_coef = 300 / Sheet.Parent.Windows(1).Zoom
Set area = Sheet.Range("M1:X27")
area.CopyPicture xlPrinter
Set chartobj = Sheet.ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Activate
chartobj.Chart.Paste
chartobj.Chart.Export sFilePath, "png"
chartobj.Delete
ActiveWindow.View = sView
Application.ScreenUpdating = True
MsgBox ("Export completed! The file can be found here:" & Chr(10) & Chr(10) & sFilePath)
End Sub