Open Workbook Read Only and hide select worksheets
"imelda1ab" wrote in message
...
On Mar 7, 4:37 pm, "Peter T" <peter_t@discussions wrote:
"imelda1ab" wrote in message
...
On Mar 7, 12:00 pm, "Peter T" <peter_t@discussions wrote:
"imelda1ab" wrote in message
...
On Mar 7, 10:38 am, "Peter T" <peter_t@discussions wrote:
<snip
Regards,
Peter T- Hide quoted text -
- Show quoted text -
You are quite simply my hero. I'm working on Multi-Select List Boxes
next. Are you a pro at those too?
Again, thanks a million.
------------------------------
Yep, 'pro' is my middle name. If I don't know it I'll just bluff it, as I
did with most of my answers in this thread !
Regards,
Peter T
Peter T, Peter T, Where You Be Peter T?
Okay, I have this bad boy working like a charm EXCEPT when I close
Doc2 I am still being prompted with the "Do you wish to save changes?"
dialog. If Doc2 is opened directly at the source as read-only and
then closed, but when Doc2 is launched via the macro in Doc1, I
continue to be prompted. Is there a way to avoid the Save prompt when
I'm opening Doc2 from Doc1?
Code from Doc1
Sub Workbook_Open()
Workbooks.Open Filename:="C:\mac2\Doc2.xls", ReadOnly:=True
Workbooks("Doc2.xls").Activate
Dim sMacro As String
sMacro = "'Doc2.xls'!ShowAffOnly"
Application.Run sMacro
ThisWorkbook.Close False
End Sub
--------------------------------------------
Code from Doc2:
Private Sub Before_Save(Cancel As Boolean)
If ThisWorkbook.ReadOnly = True Then
ThisWorkbook.Saved = True
Else
ThisWorkbook.Saved = False
End Sub
Private Sub Auto_Close(Cancel As Boolean)
If ThisWorkbook.ReadOnly = True Then
ThisWorkbook.Saved = True
Else
ThisWorkbook.Saved = False
End Sub
------------------------------------------------------
Reply starts he
You'll get the save prompt when closing a file that has been flagged as
'dirty', ie after some change has occurred to the file. Do you know why your
Doc2 is thus flagged. Maybe it's after doing this
Workbooks.Open Filename:="C:\mac2\Doc2.xls", ReadOnly:=True
Workbooks("Doc2.xls").Activate
add this line immediately after
msgbox ActiveWorbook.Saved
If that's False it's 'dirty' and will trigger Save dialog unless the it's
Saved property is changed. So if .Saved returns False at this point, replace
the msgbox with
ActiveWorbook.Saved = True to remove the 'dirty' flag
If the file is getting flagged as dirty at some later stage maybe it's for
an obvious reason. Whatever, if you don't want the file to trigger the save
prompt on close there are two ways to prevent it -
- set the file's .Saved property True
(various examples of doing that throughout this thread)
- programmatically close it like this
Workbooks("Doc2.xls").Close False
Regards,
Peter T
|