Solved

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

Posted on 2013-11-12
2
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

707 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