Private sub to generate Message Box

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I need a message box to be generated when opening a workbook and #value! appears in Cell E4 (have a hyperlink to a workbook in E4)

I have tried to write code to do this, but the message box does not appear

Code:
 Private Sub Workbook_Open()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Modify the sheet name as per your requirement
    
    If ws.Range("E4").Value = "#VALUE!" Then
        MsgBox "Double Click on Hyperlink to open Managers Comm File", vbInformation, "Open Managers Comm File"
    End If
End Sub


it would be appreciated if someone could kindly amend my code
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How about this :
VBA Code:
 Private Sub Workbook_Open()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Modify the sheet name as per your requirement
    If IsError(ws.Range("E4")) Then
        If Evaluate("=ERROR.TYPE(E4)") = 3& Then
            MsgBox "Double Click on Hyperlink to open Managers Comm File", vbInformation, "Open Managers Comm File"
        End If
    End If
End Sub
 
Upvote 0
Solution
Thanks for the help. I had the code inserted in the sheet module and not the workbook Module
 
Upvote 0
Thanks for the help. I had the code inserted in the sheet module and not the workbook Module
Try fully qualifying the cell E4 as follows and see if it works:

If Evaluate("=ERROR.TYPE(Sheet1!E4)") = 3& Then

EDIT:

Just saw your last edit . Even if it now works for you, I would still recommend that you amend the code and fully-qualify the cell E4 as shown above in case Sheet1 is not the active worksheet when first opening the workbook
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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