Solved

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

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

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
Hi Rgonzo,

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

Regards, Andreas
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

771 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

9 Experts available now in Live!

Get 1:1 Help Now