A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Center All Pictures in Excel Cells



 
 
Thread Tools Display Modes
  #1  
Old May 28th, 2010, 03:29 AM posted to microsoft.public.excel.misc
Finny[_3_]
external usenet poster
 
Posts: 1
Default Center All Pictures in Excel Cells

Please help. Right now I have a UDF that I found online that lets me
insert a picture into a cell by referencing the exact location on my
hard drive where the picture resides. I also have a macro that if I
select a shape # and range value, it will center that shape in the
cell for which is referenced.

Is there a way to combine these two codes to get it to insert the
picture and also center the picture perfectly within the cell? I can
get the first code to add as many pictures as I reference, but then I
am at a loss with centering them all within the cells.

Any help that you can provide would be greatly appreciated.


INSERT PICTURE CODE START

Function ShowPic(PicFile As String) As Boolean
Dim AC As Range
Dim shp As Shape
On Error GoTo Done
Set AC = Application.Caller
ActiveSheet.Shapes.AddPicture PicFile, True, True, AC.Left, AC.Top, 5,
5
ShowPic = True
Exit Function
Done:
ShowPic = False
End Function

INSERT PICTURE CODE END

CENTER PICTURE CODE START
Sub aTest()
CenterMe ActiveSheet.Shapes(1), Range("b8")
End Sub

Sub CenterMe(shp As Shape, overcells As Range)

With overcells
shp.Left = .Left + ((.Width - shp.Width) / 2)
shp.Top = .Top + ((.Height - shp.Height) / 2)
End With
End Sub

CENTER PICTURE CODE END

  #2  
Old May 28th, 2010, 05:27 AM posted to microsoft.public.excel.misc
Jim Cone[_2_]
external usenet poster
 
Posts: 434
Default Center All Pictures in Excel Cells

Function ShowPic(PicFile As String) As Boolean
Dim AC As Range
Dim shp As Shape
On Error GoTo Done

Set AC = Application.Caller
Set shp = ActiveSheet.Shapes.AddPicture _
(PicFile, True, True, AC.Left, AC.Top, 10, 10) ' picture made larger
Call CenterMe(shp, AC) ' calls the centering sub.
ShowPic = True
Set shp = Nothing
Set AC = Nothing
Exit Function
Done:
ShowPic = False
End Function
'--
Sub CenterMe(shp As Shape, overcells As Range)
With overcells
shp.Left = .Left + ((.Width - shp.Width) / 2)
shp.Top = .Top + ((.Height - shp.Height) / 2)
End With
End Sub
--

Jim Cone
Portland, Oregon USA
( http://www.mediafire.com/PrimitiveSoftware )





"Finny"
wrote in message ...
Please help. Right now I have a UDF that I found online that lets me
insert a picture into a cell by referencing the exact location on my
hard drive where the picture resides. I also have a macro that if I
select a shape # and range value, it will center that shape in the
cell for which is referenced.

Is there a way to combine these two codes to get it to insert the
picture and also center the picture perfectly within the cell? I can
get the first code to add as many pictures as I reference, but then I
am at a loss with centering them all within the cells.
Any help that you can provide would be greatly appreciated.


INSERT PICTURE CODE START

Function ShowPic(PicFile As String) As Boolean
Dim AC As Range
Dim shp As Shape
On Error GoTo Done
Set AC = Application.Caller
ActiveSheet.Shapes.AddPicture PicFile, True, True, AC.Left, AC.Top, 5,
5
ShowPic = True
Exit Function
Done:
ShowPic = False
End Function

INSERT PICTURE CODE END

CENTER PICTURE CODE START
Sub aTest()
CenterMe ActiveSheet.Shapes(1), Range("b8")
End Sub

Sub CenterMe(shp As Shape, overcells As Range)

With overcells
shp.Left = .Left + ((.Width - shp.Width) / 2)
shp.Top = .Top + ((.Height - shp.Height) / 2)
End With
End Sub

CENTER PICTURE CODE END

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.