Solved

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

Posted on 2013-11-12
2
295 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now