You are here:

Excel/inserting images in excell

Advertisement


Question
Again I could not ask a question from your previous answer.

With some minor variations your macro worked perfectly.

I have one more request.

Is there any way that I could click on an image in column B and enlarge that image to 640X480 and then click or double click on the same image and reduce it back to 140X80?

Thanks again for all your help!

Ben

Answer
Ben

Put these in the same general module (insert=>Module in the visible basic editor)

Sub PicAction()
s = Application.Caller
Set pic = ActiveSheet.Pictures(s)
If pic.Height > 200 Then
 pic.Height = 140
 pic.Width = 80
Else
 pic.Height = 640
 pic.Width = 480
End If
End Sub


Sub checkfiles()
Dim sPath As String, sName As String
Dim sFirst As Boolean, rw As Long
Dim pic As Picture
Dim r As Range
sFirst = True
rw = 1
sPath = "C:\1. LP software05-13-1130-1630-SA-RAS-mpeg4-\"
'sPath = "D:\C_Drive\Data\"
sName = Dir(sPath & "*.jpg")
Do While sName <> ""
 If sFirst Then
    Set r = Cells(rw, 1)
    r.Value = sName
    r.VerticalAlignment = xlBottom  ' text at the bottom
    r.HorizontalAlignment = xlCenter
    Set pic = ActiveSheet.Pictures.Insert(sPath & sName)
    pic.ShapeRange.LockAspectRatio = False
    pic.Top = r.Top   ' Picture at the top
    pic.Left = r.Left
    'Column A, image does not need to be reduced
'    pic.Height = 140
'    pic.Width = 80
     pic.OnAction = "PicAction"
    sFirst = False
 Else
    
    Set r = Cells(rw, 2)
    r.Value = sName
    r.VerticalAlignment = xlBottom  ' text at the bottom
    r.HorizontalAlignment = xlCenter
    Set pic = ActiveSheet.Pictures.Insert(sPath & sName)
    pic.ShapeRange.LockAspectRatio = False
    pic.Top = r.Top    ' Picture at the top
    pic.Left = r.Left
    ' column B, image needs to be reduced
    pic.Height = 140
    pic.Width = 80
    pic.OnAction = "PicAction"
    Cells(rw, 2) = sName
    sFirst = True
    rw = rw + 1
 End If
 sName = Dir()
Loop
End Sub

Tested and worked for me

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.