Pictures.Insert(wURL) does not work with some images

drom

Well-known Member
Joined
Mar 20, 2005
Messages
543
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and thanks in advance !!

I have a range with website images on it eg:
Both images are existing images (if I copy and paste the lines in google you can see the images)

However I do not know why when trying to paste the images 48 in a cell (the second line) I CANT

I am using the following macro to paste the website images in my cell.offset(,1)

VBA Code:
Sub mToInsertURLpicture()
  On Error Resume Next:                         Application.ScreenUpdating = False
Dim WKBvba As Workbook:                         Set WKBvba = ThisWorkbook
Dim WKBactive As Workbook:                      Set WKBactive = ActiveWorkbook
  Dim wActSht As String:                        wActSht = ActiveSheet.Name
    Dim rCell As Range:                         Set rCell = ActiveCell
Dim wURL As String:                             wURL = rCell
  Dim Pic As Picture
Dim Shp As Shape

    
    Err.Clear
    'rCell.Select
    If wURL <> "" Then
      If Left(LCase(wURL), 4) = "http" Then '://" Or Left(LCase(wURL), 8) = "https://" Then
        Err.Clear
        Set Pic = Nothing:                    Set Pic = WKBactive.Sheets(wActSht).Pictures.Insert(wURL)
        'If Err <> 0 Then
        If Pic Is Nothing Then
          rCell.Offset(, 1) = "Wrong"
        Else
          rCell.Offset(, 1) = "OK"
        End If
      End If
    End If

  When Activecell


End Sub

Any IDEA whats going wrong, what am I missing??
 

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
I don't know why, but it works if you use .JPG rather than .jpg at the end of the file name
 
Upvote 0
Solution
I don't know why, but it works if you use .JPG rather than .jpg at the end of the file name
I have been using what you have done (I don't understand why in some cases works) 'Not in all of them so...:

using your code, I now use:

Set PIC = Nothing: Set PIC = Sheets(wActSht).Pictures.Insert(wURL)
If PIC Is Nothing Then
Set PIC = Nothing: Set PIC = Sheets(wActSht).Pictures.Insert(UCase(wURL))
End If
If PIC Is Nothing Then
Set PIC = Nothing: Set PIC = Sheets(wActSht).Pictures.Insert(Left(LCase(wURL), Len(wURL) - 4) & UCase(Right(wURL, 4)))
End If

and works always
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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