Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Open Workbook Read Only and hide select worksheets

On Mar 27, 3:36*am, "Peter T" <peter_t@discussions wrote:
"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- Hide quoted text -

- Show quoted text -


I don't know how much you earn doing whatever it is that you do, but
it's not enough. You're incredible. Thanks so much.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use hyperlink to open workbook read only? Clif McIrvin[_2_] Excel Discussion (Misc queries) 3 April 9th 10 02:48 AM
Need VBA Code to Open a Workbook in read only zulfer7 Excel Discussion (Misc queries) 1 July 10th 06 11:00 PM
Running a macro in a open as read-o Workbook TBarreiro Excel Programming 0 September 2nd 05 04:06 PM
Running a macro in a open as read-o Workbook TBarreiro Excel Programming 0 September 2nd 05 04:02 PM
workbook open read only without prompt turbogoat Excel Programming 1 August 26th 04 10:44 PM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"