ststern45
Well-known Member
- Joined
- Sep 17, 2005
- Messages
- 974
- Office Version
- 365
- 2010
- Platform
- Windows
I wanted to ask if it would be possible to change the following code below with the following:
1. Remove the message box
2. Replace with a cell range
Thank you!!
Sub Select_ExportRangeAsPictureOnDesktopLeft1()
'Sep 12, 2016
Const FName As String = "C:\Users\stste\Desktop\Left1.jpg"
Dim pic_rng As Range
Set pic_rng = Selection
If MsgBox("select the desired range ??", vbOKCancel) = vbCancel Then Exit Sub
Dim ShTemp As Worksheet
Dim ChTemp As Chart
'Dim PicTemp As Picture
Application.ScreenUpdating = False
Set ShTemp = Worksheets.Add
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=ShTemp.Name
With ActiveChart.Parent
.Height = pic_rng.Height
.Width = pic_rng.Width
End With
Set ChTemp = ActiveChart
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChTemp.Paste
'Set PicTemp = Selection
ChTemp.Export Filename:=FName, FilterName:="jpg"
Application.DisplayAlerts = False
ShTemp.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
1. Remove the message box
2. Replace with a cell range
Thank you!!
Sub Select_ExportRangeAsPictureOnDesktopLeft1()
'Sep 12, 2016
Const FName As String = "C:\Users\stste\Desktop\Left1.jpg"
Dim pic_rng As Range
Set pic_rng = Selection
If MsgBox("select the desired range ??", vbOKCancel) = vbCancel Then Exit Sub
Dim ShTemp As Worksheet
Dim ChTemp As Chart
'Dim PicTemp As Picture
Application.ScreenUpdating = False
Set ShTemp = Worksheets.Add
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=ShTemp.Name
With ActiveChart.Parent
.Height = pic_rng.Height
.Width = pic_rng.Width
End With
Set ChTemp = ActiveChart
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChTemp.Paste
'Set PicTemp = Selection
ChTemp.Export Filename:=FName, FilterName:="jpg"
Application.DisplayAlerts = False
ShTemp.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub