VBA for Images Location

naresh_ank

New Member
Joined
Nov 20, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello Forum Group,
Grettingss...

Iam using below code to insert the Images in the Excel sheet ...

NewFN = "C:\Users\ankat\OneDrive\Pictures\Screen-Shots\Testcase1.jpg"
ActiveSheet.Shapes.AddPicture(Filename:=NewFN, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=1, Top:=1, Width:=140, Height:=195).Select

Here myself facing difficuly to insert the Image at Exact cell location,iam using Left and Top corredinates but if any body changes cell high then the corredinates are chageing and image is moving to other areas...

My self used "Range("A86").Select" , "ActiveCell.Select " but iam unable place the Image at this cell...

Please suggest the method to insert the Image @ cell loaction in the Excel sheet

Thanks





Please suggest how i can use
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
50,868
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
NewFN = "C:\Users\ankat\OneDrive\Pictures\Screen-Shots\Testcase1.jpg"
With Range("A86")
   ActiveSheet.Shapes.AddPicture(FileName:=NewFN, _
   LinkToFile:=msoFalse, _
   SaveWithDocument:=msoTrue, _
   Left:=.Left, Top:=.Top, Width:=140, Height:=195).Select
End With
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,797
VBA Code:
Option Explicit

Sub Picture()

Range("F6").Select 'This is where picture will be inserted

ActiveSheet.Pictures.Insert("C:\Users\jimga\Desktop\stamp.png").Select
'Path to where pictures are stored - Edit as required

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This resizes the picture
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Application.ScreenUpdating = False

With Selection
.Left = Range("F6").Left                '<--- change cell as required
.Top = Range("f6").Top                  '<--- change cell as required
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 100#
.ShapeRange.Width = 100#
.ShapeRange.Rotation = 0#
End With

Application.ScreenUpdating = True

Exit Sub

ErrNoPhoto:
MsgBox "Unable to Find Photo" 'Shows message box if picture not found
Exit Sub


End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,756
Messages
5,574,050
Members
412,565
Latest member
roberttaekim
Top