Monitor next workbook to open

TangentialAccel

New Member
Joined
Jan 22, 2018
Messages
7
Hi guys,
<o:p></o:p>
I’m trying to write VB code in workbook A that monitors the next workbook to open (we’ll call it workbook B) and reports back to workbook A whether or not Workbook B is read-only or not. Workbook B could be a VBA enabled or a non-VBA enabled workbook and could be any workbook opened by the user, so the file path and file name wouldn’t be known. I would like Workbook A to report a Boolean value – True if workbook B is read-only, and False if workbook B is not read-only. Below is what Ihave so far, but I know that I’m missing something... I'm using Excel 2007 btw.
<o:p></o:p>
Code:
'Code in ThisWorkbook object in Workbook A:
Public ro As Boolean

Private Sub workbook_activate()
If ActiveWorkbook.ReadOnlyRecommended = True Then
 MsgBox "This workbook is saved as read-only recommended"
 ro = True
Else
 ro = False
End If
End Sub
Thanks in advance!<o:p></o:p>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
add this code in the THISWORKBOOK code module (in workbook A). Then save, close and reopen workbook A and try to open another workbook

Code:
 Dim WithEvents oApp As Excel.Application

Private Sub oApp_WorkbookOpen(ByVal Wb As Workbook)
    MsgBox "The Excel File: " & Wb.Name & " is: " & IIf(Wb.ReadOnly, "Read Only", "Not Read Only")
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set oApp = Nothing
End Sub

Private Sub Workbook_Open()
    Set oApp = Excel.Application
End Sub
 
Upvote 0
How about
Code:
Option Explicit

'Code in ThisWorkbook object in Workbook A:
Public ro As Boolean

Private Sub Workbook_Deactivate()
   If ActiveWorkbook.ReadOnlyRecommended = True Then
    MsgBox "This workbook is saved as read-only recommended"
    ro = True
   Else
    ro = False
   End If
MsgBox ro

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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