Connecting Tech Pros Worldwide Help | Site Map

Insert a picture in specific cells in Excel

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: 4 Weeks Ago
Hi Everyone!

I tried to insert a picture in specific cells and I have coded a small VBA for Excel 2007. Unfortunately the macro only opens and inserts a picture in the active sheet but it should add the picture in cell B3, H4 and L6 in this sheet.

Could you please help me to fix the problem.

thx a lot!

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub Macro1()
  3.  
  4. Dim Pict
  5. Dim ImgFileFormat As String
  6. Dim PictCell As Range
  7. Dim Ans As Integer
  8.  
  9. ImgFileFormat = "Image Files (*.bmp),others, tif (*.tif),*.tif, jpg (*.jpg),*.jpg"
  10.  
  11. GetPict:
  12. Pict = Application.GetOpenFilename(ImgFileFormat)
  13. If Pict = False Then End
  14.  
  15. ActiveSheet.Pictures.Insert(Pict).Select
  16.  
  17. End Sub
  18.  
  19.  
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,260
#2: 1 Week Ago

re: Insert a picture in specific cells in Excel


Sending over to Access forum for a closer look; have you tried searching beforehand, might have been something posted on this, give that a try while you wait if need be.

In a bit, good luck!
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 782
#3: 1 Week Ago

re: Insert a picture in specific cells in Excel


Here is the code I got
Expand|Select|Wrap|Line Numbers
  1. Sub Macro1()
  2. '
  3. ' Macro1 Macro
  4. ' Macro recorded 9/11/2009 by Graham
  5. '
  6.  
  7. '
  8.     Range("G13").Select
  9.     ActiveSheet.Pictures.Insert( _
  10.         "C:\Documents and Settings\Graham\My Documents\My Pictures\barb3.png").Select
  11. End Sub
  12.  
HINT
I always find that if I am usure how to do something using VBA within Word or excel, then

1) record a new macro
2) perform the steps that I want my code to do
3) stop recording the macro
4) Go check the code the macro recorder generated and adjust it to suit my needs
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#4: 1 Week Ago

re: Insert a picture in specific cells in Excel


OK the short answer to your question is you can't insert a picture into a specific cell in Excel. There is a facility to add a background image to a comment in Excel 2007 but not sure offhand how you would code this.

Your best option is to position your image on the sheet after inserting it I think.

Mary
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 782
#5: 1 Week Ago

re: Insert a picture in specific cells in Excel


msquared is absolutely correct

The only thing the code I posted does is position the top left corner of the picture at the top left corner of the selected cell. It's not actually in the cell.
Reply


Similar Microsoft Access / VBA bytes