Macro to insert a jpg from file in specific location on a worksheet

gmmom00

New Member
Joined
Apr 6, 2012
Messages
46
All,
I am trying to write a macro to take a logo in a file logo.jpg and insert it into to the top left corner of each of three worksheets in a workbook. Not in a header, just in the upper left corner of the worksheets. Is this possible? Does the jpg of the logo have to be somewhere else in the workbook or in another open excel file? Normally I make my macros by recording and then clean up the code. Can I record this marcro?
Thanks,
h
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
The top left corner of every worksheet is cell A1. I'm sure you know that, so maybe by "top left corner" you mean whichever cell happens to be in the visible top left corner at any given time. If so, that would not give much structure to your workbook design, seeing as that visible top left cell could be one of millions of cells at the time of macro execution, thereby placing your logo file in unpredictable locales...not a good idea.

Be that as it may, assuming...

• You want the picture in cell A1
• The picture is named logo.jpg
• The picture resides on your C drive in the folder named YourFilePath
• The three destination worksheets are named Sheet1, Sheet2, and Sheet3

...this works, just tested no problem:

Code:
Sub Test1()
Dim sFile As String
sFile = "C:\YourFilePath\logo.jpg"

If Dir(sFile) = "" Then
MsgBox "Picture file was not found in path!", , "No such animal"
Exit Sub
End If

Dim pct As Picture, iLeft#, iTop#
Dim SheetList As Variant, SheetItem As Variant
SheetList = Array("Sheet1", "Sheet2", "Sheet3")

For Each SheetItem In SheetList
With Sheets(SheetItem)
With .Range("A1")
iLeft = .Left: iTop = .Top
End With
Set pct = .Pictures.Insert(sFile)
pct.Left = iLeft
pct.Top = iTop
End With
Next SheetItem 
End Sub
 

gmmom00

New Member
Joined
Apr 6, 2012
Messages
46
Tom,
Thank-you for your reply, and all your assumptions were correct, especially A1. Thank-you, I will try this and let you know if I have any additional questions.
So much appreciated!
h
 

Watch MrExcel Video

Forum statistics

Threads
1,122,961
Messages
5,599,061
Members
414,281
Latest member
Engjamal2021

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
Top