jp.bolsairriga
15-08-2016 14:12:13
Bom dia a todos.
preciso salvar alguma parte da minha planilha como imagem, achei um código excelente na web, fiz algumas alterações.
Até ai tudo bem, mais preciso alterar este código de forma que eu posso escolher o nome do arquivo e o local que o mesmo será salvo.
Já fiz algumas pesquisas, mais nada até agora
segue o código:
Sub Salva_Range_Como_Imagem()
'http://tech.groups.yahoo.com/group/ms_e ... sage/38865
' =========================================
' Code to save selected Excel Range as Image
' adjusted by Pascal Daulton 15-Sep-2011
'Readaptado em 16-09-2011 por RLM
' =========================================
Dim sRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim sPath As String
sPath = ThisWorkbook.Path
'Acrescenta a barra invertida "\"; se necessaria
If Right(sPath, 1) <> "\" Then
sPath = sPath & "\"
Else
sPath = sPath
End If
'Acrescenta nome arquivo na range F2
sPath = sPath & Sheets("Plan1").Range("F2").Value & ".jpeg"
Set sRange = Range("B2:C6")
With sRange
.CopyPicture xlScreen, xlPicture
Set oCht = ActiveSheet.ChartObjects.Add(50, 50, .Width + 5, .Height + 5).Chart
End With
With oCht
.Paste
.Shapes(1).Left = -.ChartArea.Left
.Shapes(1).Top = -.ChartArea.Top
.Parent.Width = sRange.Width
.Parent.Height = sRange.Height
.Export Filename:=sPath, Filtername:="jpeg"
.Parent.Delete
End With
End Sub
preciso salvar alguma parte da minha planilha como imagem, achei um código excelente na web, fiz algumas alterações.
Até ai tudo bem, mais preciso alterar este código de forma que eu posso escolher o nome do arquivo e o local que o mesmo será salvo.
Já fiz algumas pesquisas, mais nada até agora
segue o código:
Sub Salva_Range_Como_Imagem()
'http://tech.groups.yahoo.com/group/ms_e ... sage/38865
' =========================================
' Code to save selected Excel Range as Image
' adjusted by Pascal Daulton 15-Sep-2011
'Readaptado em 16-09-2011 por RLM
' =========================================
Dim sRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim sPath As String
sPath = ThisWorkbook.Path
'Acrescenta a barra invertida "\"; se necessaria
If Right(sPath, 1) <> "\" Then
sPath = sPath & "\"
Else
sPath = sPath
End If
'Acrescenta nome arquivo na range F2
sPath = sPath & Sheets("Plan1").Range("F2").Value & ".jpeg"
Set sRange = Range("B2:C6")
With sRange
.CopyPicture xlScreen, xlPicture
Set oCht = ActiveSheet.ChartObjects.Add(50, 50, .Width + 5, .Height + 5).Chart
End With
With oCht
.Paste
.Shapes(1).Left = -.ChartArea.Left
.Shapes(1).Top = -.ChartArea.Top
.Parent.Width = sRange.Width
.Parent.Height = sRange.Height
.Export Filename:=sPath, Filtername:="jpeg"
.Parent.Delete
End With
End Sub