Public Function FileFolderExistsBins(strFullPath As String) As Boolean
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExistsBins = True
EarlyExit:
On Error GoTo 0
End Function
Sub exportPic1()
Dim picRange As Range
Dim picChart As Chart
Dim name1 As String
Set picRange = Range("C2:H23")
name1 = "filename" & ".png"
'Check to see if file already exists, if so deletes it so new file can be saved
If FileFolderExistsBins(name1) Then
Kill (name1)
Else
End If
'Creates a chart and pastes the image in it
Set picChart = ActiveSheet.ChartObjects.Add(Left:=0, _
Top:=picRange.Top + picRange.Height + 10, _
Width:=picRange.Width, Height:=picRange.Height).Chart
With ActiveSheet.Shapes(picChart.Parent.name)
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
picRange.CopyPicture xlScreen, xlPicture
picChart.Paste
'Exports picture to file
picChart.Export Filename:=name1, Filtername:="png"
'Deletes Chart from sheet
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each wsItem In ThisWorkbook.Worksheets
For Each chtObj In wsItem.ChartObjects
chtObj.Delete
Next
Next
Application.ScreenUpdating = True
End If
End Sub
Sub exportPicture()
Dim oRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim name1 As String
Application.ScreenUpdating = False
'Create file name
name1 = "full path & filename" & ".png" '|||||||||||||||||||||enter the full name and filepath
'Check to see if file already exists, if so deletes it so new file can be saved
If FileFolderExists(name1) Then
Kill (name1)
Else
End If
'Creates a chart and pastes the image in it
Set oRange = Range("B3:D9") '|||||||||||||||||||||This is what range your picture will be in.
Set oCht = ActiveSheet.ChartObjects.Add(Left:=0, _
Top:=oRange.Top + oRange.Height + 10, _
Width:=oRange.Width, Height:=oRange.Height).Chart
With ActiveSheet.Shapes(oCht.Parent.Name)
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
oRange.CopyPicture xlScreen, xlPicture
oCht.Paste
'Exports
oCht.Export Filename:=name1, Filtername:="png"
'Deletes Chart from sheet
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each wsItem In ThisWorkbook.Worksheets
For Each chtObj In wsItem.ChartObjects
chtObj.Delete
Next
Next
Application.ScreenUpdating = True
End Sub
Sub exportPicture()
Dim oRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim name1 As String
Application.ScreenUpdating = False
'Create file name
name1 = "full path & filename" & ".png" '|||||||||||||||||||||enter the full name and filepath
'Check to see if file already exists, if so deletes it so new file can be saved
If FileFolderExists(name1) Then
Kill (name1)
Else
End If
'Creates a chart and pastes the image in it
'Set oRange = Range("B3:D9") '|||||||||||||||||||||This is what range your picture will be in.
Set oRange = Selection
With ActiveChart
Set oCht = ActiveSheet.ChartObjects.Add(Left:=0, _
Top:=oRange.Top + oRange.Height + 10, _
Width:=oRange.Width, Height:=oRange.Height).Chart
End With
With ActiveSheet.Shapes(oCht.Parent.Name)
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
oRange.CopyPicture xlScreen, xlPicture
oCht.Paste
'Exports
oCht.Export Filename:=name1, Filtername:="png"
'Deletes Chart from sheet
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each wsItem In ThisWorkbook.Worksheets
For Each chtObj In wsItem.ChartObjects
chtObj.Delete
Next
Next
Application.ScreenUpdating = True
End Sub
I guess the only hitch to this is you have to select a range, it will not export selected pictures, only what is in a selected range. That said, you can put whatever you want inside that range and it becomes a part of the image. I use this method to make maps for work with labels and arrows, etc. made with Excel.