Excel VBA Insert Picture into Cell

Jaye Cavallo

New Member
Joined
Mar 10, 2022
Messages
49
Office Version
  1. 2016
Platform
  1. Windows
I have been trying to insert a picture into a cell using VBA. I found this code on Google. I am using Excel 365. Can someone explain to me why I receive a syntax error with the following code?

Sub InsertImageIntoCell()

Dim imageURL As String

imageURL = "https://www.example.com/logo.png" ' Replace with your image URL

With ThisWorkbook.Worksheets("Sheet1") ' Change "Sheet1" to your desired sheet

.Range("A1").Value = "=IMAGE(""" & imageURL & "", 0)" ' Insert image in cell A1, fitting to cell

End With

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You are missing a nested double quote. Try
.Range("A1").Value = "=IMAGE(""" & imageURL & """, 0)"
Please post more than a few lines of code within code tags and maintain proper indentation (use vba button on posting toolbar to get the tags).
 
Upvote 0
Solution
Sorry, but that is all the code I currently have within the tags. I am running it as a macro as a test before I build out what I want.

Thank you for your solution. The additional " does work in some instances. Now I have to figure out why I get a #value error for other https URL's that I assign to the imageURL variable.
 
Upvote 0
that is all the code I currently have within the tags
Not sure what that means because you did not use code tags in your post. #Value error has various causes; incorrect data type probably includes empty strings or nulls (because a cell in the formula contains no value).
 
Upvote 0

Forum statistics

Threads
1,226,463
Messages
6,191,181
Members
453,645
Latest member
BOUCHOUATA

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