Trying to write VBA to test if the IMAGE function is supported

Status
Not open for further replies.

bisel

Active Member
Joined
Jan 4, 2010
Messages
264
Office Version
  1. 365
Platform
  1. Windows
Greetings All,

I have an Excel application that will use the Excel function to insert an image inside a cell. It is my understanding that the function to insert an image inside a cell is also associated with the IMAGE function which is available in Excel 365 but not earlier versions such as Excel 2019.

I was searching around and found VBA code I adapted for my use ...

VBA Code:
Sub CheckExcel ()
' Attempt to use the IMAGE function.
  On Error Resume Next
  Sheet5.Range("excelIMAGEtarget").Formula = "=IMAGE(""https://reservestudyhoa.com/images/diyimage_small.jpg"")"
    
' Check if the function was accepted
    If Err.Number = 0 Then
        Sheet5.Range("excelsupported").Value = "TRUE"
        Err.Clear
        MsgBox "This version of Excel supports the IMAGE function." 
        On Error GoTo 0
        Exit Sub
    Else
        Sheet5.Range("excelsupported").Value = "FALSE"
        MsgBox "This version of Excel does not support the IMAGE function." 

        Err.Clear
        On Error GoTo 0
        Exit Sub
    End If

End Sub

I must be doing something wrong because I can never force the error condition. For example, if change this line


VBA Code:
Sheet5.Range("excelIMAGEtarget").Formula = "=IMAGE(""https://reservestudyhoa.com/images/diyimage_small.jpg"")"

to this ...
VBA Code:
Sheet5.Range("excelIMAGEtarget").Formula = "=IMAGEX(""https://reservestudyhoa.com/images/diyimage_small.jpg"")"

The resulting target cell displays #NAME which I would expect. But, the VBA code does not trap the error condition.

Appreciate any help.

Regards,

Steve
 
Isn't this the same question as here?
 
Upvote 0
Isn't this the same question as here?
Sort of the same. Certainly the same issue I am trying to solve. I have tried various bits of code and I am hoping that this bit of code will check what I need ...

VBA Code:
Private Sub Workbook_Open()

Dim excelbuild_short As String
Dim excelVersion As String

' Check if Excel supports PIC

     excelVersion = Application.Version * 1   'Convert string to number
     excelBuildShort = Application.Build * 1  'Convert string to number

    If excelVersion >= 16 And excelBuildShort >= 13426 Then
        Err.Clear
        MsgBox "This version of Excel supports the PICTURE IN CELL function."
        On Error GoTo 0
        Exit Sub
    Else
        MsgBox "This version of Excel DOES NOT support the PICTURE IN CELL function."
        Err.Clear
        On Error GoTo 0
    End If
End Sub


The above code works with my installed Excel which is Excel 365. Excel Version number of 16 will apply to several "versions" of Excel including 365, 2016, 2019, 2021, and 2024. But I am hoping that including the test to determine that the version number is >= 16 ... AND ... the Build number is >= 16529 that I am accomplishing my intention.
 
Upvote 0
In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,226,771
Messages
6,192,919
Members
453,767
Latest member
922aloose

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