LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 277
Default Chop picture in VBA?


I found the refined result I came up with...

Sub Pop()
' This pops the image in from the data archive,
'

On Error Resume Next
ActiveSheet.Shapes("Popped").Delete
InsertPicture Range("B6").Value, _
Range("B6:G33"), "Popped"
End Sub

Sub InsertPicture(PictureFileName As String, TargetCells As Range,
picName As String)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) < "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
'Name the picture so you can delete it later....
p.Name = picName
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub



On Thu, 03 Jan 2013 09:51:12 +0100, "Charlotte E." wrote:

snip long lines (Usenet rules)

Ben

Sub CropIt()
Dim sShape As Shape
Dim sPicture As Shape

Set sShape = Sheet1.Shapes("Rectangle 1")
Set sPicture = Sheet1.Shapes("Picture 4")

With sPicture.PictureFormat 'Reset picture size, then crop to shape size
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
.CropRight = sPicture.Left + sPicture.Width - sShape.Left - sShape.Width
.CropBottom = sPicture.Top + sPicture.Height - sShape.Top - sShape.Height
.CropLeft = sShape.Left - sPicture.Left
.CropTop = sShape.Top - sPicture.Top
End With

End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect a number to a picture bank and import that picture to exce Dennis Hedo Excel Discussion (Misc queries) 1 March 22nd 10 02:17 PM
Chop off the last seven characters in a column Michael Grammas Excel Discussion (Misc queries) 1 August 10th 07 09:12 PM
insert a picture in to a comment but picture not save on hard disk Pablo Excel Discussion (Misc queries) 0 February 21st 07 03:48 PM
chop off extra characters in excel [email protected] Excel Discussion (Misc queries) 6 June 22nd 06 04:20 AM
Chop off parts of the statement 0-0 Wai Wai ^-^ Excel Worksheet Functions 1 April 23rd 06 10:01 AM


All times are GMT +1. The time now is 01:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"