0

I'm using the following code to grab an image (of a part held on a SharePoint site) to display in an excel sheet. I'd like to use the user's own Active Directory credentials to access the url. The code I've got so far is:

Dim Request As Object
Dim ResponseStatus As Variant
Dim ImgURL As String
ImgURL = "https://someValidURL/" & ExtraPartNo & ".jpg"

    Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")

    With Request
        .Open "GET", ImgURL, True
        .Send
        .WaitForResponse
        ResponseStatus = .StatusText
    End With
    Set Request = Nothing

    If ResponseStatus = "OK" Then
        ImgURL = "https://someValidURL/" & ExrtaPartNo & ".jpg"
    Else
        SetterImgURL = "https://someValidURL/AwaitingImage.jpg"
    End If

The idea is to display an image of a part if it exists but if it doesn't then display the AwaitingImage.jpg

braX
  • 11,506
  • 5
  • 20
  • 33
  • That should already be using the user's credentials? You should use `False` as the last argument to `Open` though, or your code will not wait for a response. And use HEAD not GET since you only need to know if there's an image there or not - no need to download it for that. – Tim Williams Feb 15 '18 at 07:08
  • Thanks Tim. I made the changes you suggested but I'm still getting the same problem. I think it may be an Active Directory issue rather than an excel one. The sheet pulls in the AwaitingImage.jpg which is in the same directory as the images I want but the ResponseStatus variable is always "Unauthorized". Thanks for your help. I'll do some more investigating. – Kev Williams Feb 15 '18 at 08:53
  • Maybe try xmlhttp instead of Winhttp. – Tim Williams Feb 15 '18 at 15:46

0 Answers0