Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default How to scale image to fit inside a merged cell?

Below is my VBA script to dynamically insert and size an image to a merged
cell.

My questions are, can I:
- scale the image to maximum inside a merged cell, while keeping its
original height to width ratio (instead of distorting the image scale to the
full merge cell size as it does now)?
- change the caption of the command button to "edit image" if an image has
been inserted, and change back to "insert image" if nothing is inserted?

Any help would be appreciated :-)

-------------------------------------------------
Private Sub CommandButton_Click()

Dim ImageCell As Range
Set ImageCell = Sheet3.Range("B10").MergeArea

' Go to "screen dump" input merged cell (B10:AK30)
ImageCell.Select

' Open "Insert Picture" pop-up window
Application.Dialogs(xlDialogInsertPicture).Show

' Quite action if nothing is selected
On Error Resume Next

' Otherwise size the image selection to full merged cell size
With Selection
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
.Placement = xlMoveAndSize
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default How to scale image to fit inside a merged cell?

Dimensions of merged area: ImageCell.MergeArea.Width etc.

To scale without changing the aspect ratio, calculate the ratios of [pic
width/range width] and [pic height/range height]. Use whichever ration is
appropriate to scale *both dimensions* of the picture.


Tim



"Sam Kuo" wrote in message
...
Below is my VBA script to dynamically insert and size an image to a merged
cell.

My questions are, can I:
- scale the image to maximum inside a merged cell, while keeping its
original height to width ratio (instead of distorting the image scale to
the
full merge cell size as it does now)?
- change the caption of the command button to "edit image" if an image has
been inserted, and change back to "insert image" if nothing is inserted?

Any help would be appreciated :-)

-------------------------------------------------
Private Sub CommandButton_Click()

Dim ImageCell As Range
Set ImageCell = Sheet3.Range("B10").MergeArea

' Go to "screen dump" input merged cell (B10:AK30)
ImageCell.Select

' Open "Insert Picture" pop-up window
Application.Dialogs(xlDialogInsertPicture).Show

' Quite action if nothing is selected
On Error Resume Next

' Otherwise size the image selection to full merged cell size
With Selection
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
.Placement = xlMoveAndSize
End With

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default How to scale image to fit inside a merged cell?

Thanks Tim. I was thinking of the same plan of attack, but don't know how to
execute in VBA. It'd be much appreciated if you (or anyone) can help...

In addition to the above questions (yes I know it's frustrating), I'd also
need to be able to delete the existing picture (if any) before inserting the
new one, so that only one image is shown at all time. Any idea how to do this
in VBA??

Many thanks!


"Tim Williams" wrote:

Dimensions of merged area: ImageCell.MergeArea.Width etc.

To scale without changing the aspect ratio, calculate the ratios of [pic
width/range width] and [pic height/range height]. Use whichever ration is
appropriate to scale *both dimensions* of the picture.


Tim



"Sam Kuo" wrote in message
...
Below is my VBA script to dynamically insert and size an image to a merged
cell.

My questions are, can I:
- scale the image to maximum inside a merged cell, while keeping its
original height to width ratio (instead of distorting the image scale to
the
full merge cell size as it does now)?
- change the caption of the command button to "edit image" if an image has
been inserted, and change back to "insert image" if nothing is inserted?

Any help would be appreciated :-)

-------------------------------------------------
Private Sub CommandButton_Click()

Dim ImageCell As Range
Set ImageCell = Sheet3.Range("B10").MergeArea

' Go to "screen dump" input merged cell (B10:AK30)
ImageCell.Select

' Open "Insert Picture" pop-up window
Application.Dialogs(xlDialogInsertPicture).Show

' Quite action if nothing is selected
On Error Resume Next

' Otherwise size the image selection to full merged cell size
With Selection
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
.Placement = xlMoveAndSize
End With

End Sub




Reply
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
autofit text inside merged cells Taurus_ma Excel Discussion (Misc queries) 4 September 18th 07 06:20 PM
How can I insert an image inside a comment of a cell? Javigir Excel Discussion (Misc queries) 1 February 1st 07 12:03 PM
Code an image viewer inside XL quartz[_2_] Excel Programming 4 August 15th 06 02:41 PM
Store an image inside a cell? tx12345 Excel Worksheet Functions 3 January 18th 06 04:01 AM
automatically fit an image into merged cells dave Excel Discussion (Misc queries) 1 January 26th 05 11:54 AM


All times are GMT +1. The time now is 07:02 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"