richh
Board Regular
- Joined
- Jun 24, 2007
- Messages
- 245
- Office Version
- 365
- 2016
I have a userform that has an image element on it. Depending on what criteria the user selects, the picture changes. It also has a function that follows a hyperlink on click. However, the picture will not change after following the link.
As mentioned, the pictures change fine before clicking. Once clicked, the current image will remain and changing one's selection in the user form will not change the picture.
Any help would be appreciated!
Code:
'Portion of the main code that alters the image
If log.Cells(CInt(row), 10).Hyperlinks.Count > 0 Then
Me.wLink.Caption = log.Cells(CInt(row), 10).Hyperlinks(1).Address
Else
Me.wLink.Caption = ""
End If
Me.pic.Picture = LoadPicture(vbNullString) 'attempt to clear the picture before grabbing a new one
If Dir(ThisWorkbook.path & "\itemPics", vbDirectory) <> "" Then 'check to see if directory exists
If Dir(ThisWorkbook.path & "\itemPics\" & log.Cells(CInt(row), 2).Value & "_" & log.Cells(CInt(row), 3).Value & ".jpg") <> "" Then 'if directory exists, check to see if file is found
path = ThisWorkbook.path & "\itemPics\" & log.Cells(CInt(row), 2).Value & "_" & log.Cells(CInt(row), 3).Value & ".jpg"
Me.pic.Picture = LoadPicture(path)
Me.pic.ControlTipText = "Follow link"
Else
Me.pic.ControlTipText = "Image not found"
End If
Else
Me.pic.ControlTipText = "Image directory not found. This workbook must remain in the CATALOG folder to access the image files."
End If
'*************************************************
'The private sub to follow a link
'adapted from https://social.msdn.microsoft.com/Forums/en-US/42fbea0d-3977-480f-a4c3-6093e34f469d/open-a-web-page-with-vba?forum=isvvba
Private Sub pic_Click()
Dim oLink As String
Dim IEapp As Object
Set IEapp = CreateObject("InternetExplorer.Application") 'Set IEapp = InternetExplorer
oLink = Me.wLink.Caption
'oLink = "https://www.google.com"
If oLink <> "" And InStr(oLink, "mailto") = 0 Then
With IEapp
.Silent = True 'No Pop-ups
.Visible = True 'Set InternetExplorer to Visible
.Navigate oLink 'Load web page
Do While .Busy
DoEvents
Loop
Do While .ReadyState <> 4
DoEvents
Loop
End With
End If
End Sub
As mentioned, the pictures change fine before clicking. Once clicked, the current image will remain and changing one's selection in the user form will not change the picture.
Any help would be appreciated!