Nov 09 2022 10:16 AM - edited Nov 09 2022 10:21 AM
Hi,
I have had this line of code in a macro for many years
Set ImageToAdd = ActiveSheet.Shapes.AddPicture(ImageURL, True, False, _
Cells(RowToAddImage, ColumnToAddImage).Left + 6, _
Cells(RowToAddImage, ColumnToAddImage).Top + (Cells(RowToAddImage, ColumnToAddImage).Height / 2), -1, -1)
where ImageURL is a valid url for an image that is publicly available on the internet.
This works as expected in
Microsoft® Excel® for Microsoft 365 MSO (Version 2210 Build 16.0.15726.20068) 32-bit
But is throwing the following error in version 2210 Build 15726.20174
Run-time error 1004. The specified file was not found.
Could anyone advise a solution or how I should report this as an issue to MS?
Thanks,
Richard
Nov 10 2022 01:02 AM
I think this could be because the macro was placed at the worksheet level
...without being sure as don't have a full picture of the code/file/intend.
Try right-clicking on the module node in the VBA project window,
click "Insert" => "Module"
and then paste your macro into the new module
(make sure you use the macro recorded at worksheet level Clear).
Hope I could help you with these information / links.
I know I don't know anything (Socrates)
Nov 10 2022 09:08 AM
Thank you for the suggestion. Unfortunately not - the line is in a module and always has been.
Nov 11 2022 07:49 AM
Nov 12 2022 04:01 AM
Hi,
Both are valid. I've stripped the code back and it can be inserted into a blank workbook to test:
Private Sub CommandButton1_Click()
Dim ImageToAdd
Dim RowToAddImage
RowToAddImage = 2
Dim ColumnToAddImage
ColumnToAddImage = 7
Dim ImageURL As String
'ImageURL = "https://peters.co.uk/rgw/assets/covers/large/513/9781910002513.jpg" ' fails
ImageURL = "https://peters.co.uk/uploads/downloads/medium/9781910002513.jpg" 'same image, same website, works
Set ImageToAdd = ActiveSheet.Shapes.AddPicture(ImageURL, True, False, _
Cells(RowToAddImage, ColumnToAddImage).Left + 6, _
Cells(RowToAddImage, ColumnToAddImage).Top + (Cells(RowToAddImage, ColumnToAddImage).Height / 2), -1, -1)
End Sub
As you can see I've narrowed the error down - it is conditional upon the image source. It will work with an image hosted on Google or Amazon. It works with the image stored in one valid web location, but will not work in another.
My assumption at this point is that the newer builds is not treating the fail location as secure... but I have no idea why this might be the case.
Nov 12 2022 06:35 AM
Nov 14 2022 04:06 AM
Nov 14 2022 05:43 AM