Nesta época de Mídias Sociais e grande necessidade de publicarmos KPIs e Dashboards com insights baseados em informações atualizadas, termos uma solução como a demonstrada abaixo será muito útil no dia a dia.
Sub PublishExcelRangeAsImage (r As Excel.Range, stFileNamePathForImage As String, Optional stImageType = "BMP")
'
' Copies a range in Excel, converts it to a picture, and saves it as an image file.
' r = The range you want to copy and convert to an image.
' stFileNamePathForImage = Full path, without the period (.) and extension of the destination file.
' stImageType = The extension for the filename; also determines the type of image saved to disk.
' stImageType can be "bmp", "gif", or "jpg". "bmp" is default.
'
Dim c As Excel.Chart
Dim wsSave
Dim wbSave As Excel.Workbook
Dim fDisplayAlerts As Boolean
stImageType = UCase(stImageType)
'
' In case another Workbook is active, save it so we can restore it when we are done.
' We need to do this because, later, we will change the active sheet to a chart.
'
Set wbSave = Excel.ActiveWorkbook
Set wsSave = wbSave.ActiveSheet
'
' Create a temporary chart object. This is where the image will be created.
'
Set c = r.Worksheet.Parent.Charts.Add
'
' In Excel 2007, a new chart is no lonter empty; therefore, clear it.
'
c.ChartArea.Clear
c.ChartArea.Height = r.Height * 2 ' Make sure the ChartArea is bigger than
c.ChartArea.Width = r.Width * 2 ' the image, or image will be made smaller
'
' Copy the image from the range object to the chart.
'
r.CopyPicture xlScreen, xlBitmap
c.Paste
'
' Position the image, as Excel doesn't do this well on it's own.
' Note, since we cleared the chart before pasting the image,
' we can be sure that the image is the only shape on the chart.
' Thus, we are safe to directly address shape 1, from the shape
' collection and know it's the image.
'
Let c.Shapes(1).Left = 0
Let c.Shapes(1).Top = 0
Let c.Shapes(1).Height = r.Height
Let c.Shapes(1).Width = r.Width
'
' Prevent the image from resizing when we resize the chart.
'
Let c.Shapes(1).Placement = xlFreeFloating
'
' Now make the chart the same size as the image.
'
' We need to activate the chart first because of a timing issue. If we don't
' activate it, the code fails when we set the height, unless we put a delay into the code.
' Better to activate it than put in a delay.
'
c.Activate
Let c.ChartArea.Height = r.Height
Let c.ChartArea.Width = r.Width
'
' Save the image as a file.
'
c.Export stFileNamePathForImage & "." & stImageType, stImageType
'
' We are done. Delete the chart. Note, we first need to turn off alerts, or else,
' Excel prompts us to make sure we really want to delete it.
'
Let fDisplayAlerts = Application.DisplayAlerts
Let Application.DisplayAlerts = False
c.Delete
Let Application.DisplayAlerts = fDisplayAlerts
Set c = Nothing
'
' Return focus back to the original workbook/worksheet that was active
' when this code began.
'
wsSave.Activate
Set wbSave = Nothing
Set wsSave = Nothing
End Sub
#A&A #API #Converter #Dashboard #Imagem #KPI #PIECEOFCAKE #Text #Texto #WindowsAPI #POC #VBA
Defina a Latitude e a Longitude - Find Latitude and Longitude of any address using Google Map API and VBA
VBA Excel - Traduzindo Planilhas - MS Excel VBA Script to Translate worksheets using the Google Translate API
Excel - Manipule o Google Maps em sua Planilha - Put a Google Map in your Spreadsheet
Convertendo Texto em Imagem - Convert Text to an Image using the VBA Windows API
Correção de Métricas - For Subscripts, Superscripts and Common Typos
MS Access - Cinco Formas Manuais de Reparo
MS Access e MS Word - Técnica de Automação
Microsoft Access - Removendo Prefixo das Tabelas
Sempre Use Stored Procedures - Always Use Stored Procedures
A&A - Dados ou Informações?
Consulte-nos
⬛◼◾▪ CONTATO ▪◾◼⬛
Nenhum comentário:
Postar um comentário