Range to Image - Image Resizing

rmilzy

New Member
Joined
Aug 29, 2022
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
So I am currently working with a macro that takes multiple ranges between different sheets and uploads them to a specific shared location:

VBA Code:
Dim objChrt As Chart
  Dim rngImage As Range
  Dim strFile As String

  On Error GoTo ErrExit

  With Sheets("Sheet1")

    Set rngImage = .Range("C1:R99")

    rngImage.CopyPicture Appearance:=xlScreen, Format:=xlBitmap

    strFile = "Location1.PNG"

    Set objChrt = .ChartObjects.Add(rngImage.Left, rngImage.Top, rngImage.Width, rngImage.Height).Chart

    With objChrt
        .Parent.Activate
        .ChartArea.Format.Line.Visible = msoFalse
        .Paste
        .Export strFile
        .Parent.Delete
        End With
    
With Sheets("Sheet2")  

    Set rngImage = .Range("B8:L29")

    rngImage.CopyPicture Appearance:=xlScreen, Format:=xlBitmap

    strFile = "Location2.PNG" 

    Set objChrt = .ChartObjects.Add(rngImage.Left, rngImage.Top, rngImage.Width, rngImage.Height).Chart

    With objChrt
        .Parent.Activate
        .ChartArea.Format.Line.Visible = msoFalse
        .Paste
        .Export strFile
        .Parent.Delete
    End With
  End With
  End With

ErrExit:
  Set objChrt = Nothing
  Set rngImage = Nothing
 
End Sub

In order to efficiently utilize these images, I need the width of both images to not exceed 1920 pixels (In order to display correctly on a 1080p TV).

Is it possible to resize these images before they are uploaded?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
It is certainly possible to do that - I would recommend perhaps looking at some of the projects that Jaafar Tribak has uploaded on this this Forum, though, because it might save you some time in the long run. For example, he has a project here that will take exact image snapshots without the hassle of copying and pasting things into chart objects in order to export them. I believe there is also a project on the Forum that he posted a while back that allows you to resize images to exact dimensions, too.

 
Upvote 0
And I just found the resizing/compression routine. I hope this is helpful.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top