Inserting a picture in a worksheet

karimretina

New Member
Joined
Nov 24, 2016
Messages
4
Hello every body,

I hope every one is safe and healthy

I am trying to insert a jPG picture in a work sheet called "Rx" by suing "active x control" button, the picture is named "Logo" and saved in "C:" ,. Everything is going well except that the picture is not inserted in the target cell "C33"and always inserted in the same false cell. This is the code I'm using:

VBA Code:
Private Sub cmddisplaylogo_Click()

Dim ws As Worksheet
Set ws = Worksheets("SETTINGS")
Dim ws1 As Worksheet
Set ws1 = Worksheets("Rx")

Application.ScreenUpdating = False

Dim logoname As String, T As String
myDir = "C:\"
logoname = ws1.Range("AH1")
T = ".jpg"
ws1.Range("C33").Value = logoname
On Error GoTo Errormessage:
ActiveSheet.Shapes.AddPicture Filename:=myDir & logoname & T, Linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=100, Top:=5, Width:=100, Height:=60

Errormessage:
If Err.Number = 1004 Then

MsgBox "File does not exist."

End If
Application.ScreenUpdating = True

End Sub

I have had a look around and confused myself! Any help gratefully received!

Many thanks and stay safe

Karim
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Use ws1.Range("C33").left and ws1.Range("C33").top instead of the fixed values.
 
Upvote 0

Forum statistics

Threads
1,216,297
Messages
6,129,954
Members
449,544
Latest member
Akhil333

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top