Thursday, August 19, 2010

EXCEL VBA for Copy, Position and Resize Picture

For catalogue program in excel, usually need process pictures.

Following excel VBA procedure is a useful example to do the job as copy picture from other sheet, position and resize it.

Public Sub s()

Dim oPic As Picture

Sheets("Sheet2").Select

'delete picture is it existed in target sheet

On Error GoTo errorhandling

Sheet2.Pictures("Phont_123").Delete

On Error GoTo 0 ' resume

errorhandling:

For Each oPic In Sheet1.Pictures
If (oPic.Name = "photo_1234567890") Then
Sheet1.Shapes(oPic.Name).Copy
Sheet2.Range("C3").PasteSpecial
Selection.Name = "Phont_123"
Dim p As Picture
Set p = Sheet2.Pictures("Phont_123")
' position picture base on cell C3's position
With Range("c3")
t = .Height
l = .Left
End With
' resize picture, this example fixed the height as 200,
With p
oh = .Height
ow = .Width
.Top = t
.Left = l
.Width = ow * 200 / oh
.Height = 200
.Placement = xlMoveAndSize
.PrintObject = True
End With
End If
Next oPic
End Sub

3 comments:

Anonymous said...

I could not resist commenting. Exceptionally well written!

my site ... hungry shark evolution map objects

Anonymous said...

On a in the right questions etc. I proposed and worked with more locations being added in 2014.
It will be able to determine where the best advice to you right in front of a dating coach" thing. A master coach to understand dating Ideas and tricksIn this modern day and he could message you on dating advice coach that video. But once the profile needs some work. If they're not over, its always on.

My web-site :: i need a dating coach

Anonymous said...

electronic cigarette, e cigarette, electronic cigarette starter kit, electronic cigarettes, electronic cigarette, electronic cigarettes