Solved

Downsize graphics in Excel whose height is more than 4 cm, using VBA

Posted on 2013-11-12
2
304 Views
Last Modified: 2013-11-12
Dear Experts:

below macro, courtesy of RGonzo1971 of EE, batch inserts graphics into Column D. The corresponding paths are located into Column C.

This macro is neat and concise and works just fine.

I now would like to get this macro expanded as follows:

If the graphic's height that gets inserted in any of the cells in Column D is is more than 4 cm, the graphic has to be downsized to 4 cm max Height.

All the pictures that get inserted have already the property 'aspect ratio constrained'

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub InsertPicture()
'Macro by RGonzo1971, EE
'Insertion of Graphics in Column D. Corresponding paths are stored in Column C
'
For Each c In Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
    c.Offset(0, 1).Activate
    ActiveSheet.Pictures.Insert ( _
        c.Value2)
Next
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39641973
Hi,
pls try

Sub Macro1()
'
' Macro1 Macro
'

'
For Each c In Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
    c.Offset(0, 1).Activate
    Set Image = ActiveSheet.Pictures.Insert(c.Value2)
    If Image.Height > Application.CentimetersToPoints(4) Then
        Image.Height = Application.CentimetersToPoints(4)
    End If
        
Next
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:AndreasHermle
ID: 39643752
Hi Rgonzo,

wow, I am truly impressed :) Thank you very much for your great and professional help.

Regards, Andreas
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question