File and Don't save changes - Read Only File

M

mralmackay

I have done some VBA within Module1 of my excel spreadsheet which,
amongst other things, loads up another file and copies and pastes the
information into the spreadsheet.

This part is fine. However, when I come to go out of the spreadsheet
after I've done the copy and paste into my working one it prompts to
save the file as it sees that I've done a change. I always want this
prompt to be No to Save Changes.

How do I do this? From reviewing other posts I've tried all of the
following without avail:
Application.EnableEvents = False
ThisWorkbook.Saved = True
ActiveWorkbook.Close savechanges = False
ActiveWorkbook.Close (savechanges = False)

The only 'weird' thing about the file is that it appears to have 'Read
Only' attributes so I'm assuming this is why windows is forcing excel
to save it as a different name. I'll never need to amend this file
though and only ever need to open as read-only anyway.

Would appreciate your help as always on this.

I've included an extract below from the VBA which may help?!??! I've
tried Step Into process with different variations of close activity,
all to no avail.

Thanks in advance, Al Mackay

ChDir "H:\"
Workbooks.Open Filename:= _
"H:\Cost Centre - Liaison Contact List.xls"

Selection.AutoFilter Field:=7, Criteria1:="<>"

Range("A:A,G:G").Select
Range("G1").Activate
Selection.Copy
Windows("Prepare CSV Files.xls").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Rows("1:2").Select
Range("A2").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("C1").Select

Windows("Cost Centre - Liaison Contact List.xls").Activate
Selection.AutoFilter
Application.EnableEvents = False
ThisWorkbook.Saved = True
ActiveWorkbook.Close savechanges = False
Application.EnableEvents = False
 
M

merjet

I didn't test this with a Read Only file, but it appears your
syntax is slightly off. Try one of these:
ActiveWorkbook.Close False
ActiveWorkbook.Close SaveChanges:=False

Merjet
 
M

mralmackay

Thanks to you both. I'll sort this out shortly.

Annoyed it was so simple, but am grateful as always for your help.

Thanks again, Al.

Tom said:
You were unsuccessful because you left out the colon to mark the argument value

ActiveWorkbook.Close savechanges:=False

would be correct. Note the [:=] rather than just [=]

--
Regards,
Tom Ogilvy

I have done some VBA within Module1 of my excel spreadsheet which,
amongst other things, loads up another file and copies and pastes the
information into the spreadsheet.

This part is fine. However, when I come to go out of the spreadsheet
after I've done the copy and paste into my working one it prompts to
save the file as it sees that I've done a change. I always want this
prompt to be No to Save Changes.

How do I do this? From reviewing other posts I've tried all of the
following without avail:
Application.EnableEvents = False
ThisWorkbook.Saved = True
ActiveWorkbook.Close savechanges = False
ActiveWorkbook.Close (savechanges = False)

The only 'weird' thing about the file is that it appears to have 'Read
Only' attributes so I'm assuming this is why windows is forcing excel
to save it as a different name. I'll never need to amend this file
though and only ever need to open as read-only anyway.

Would appreciate your help as always on this.

I've included an extract below from the VBA which may help?!??! I've
tried Step Into process with different variations of close activity,
all to no avail.

Thanks in advance, Al Mackay

ChDir "H:\"
Workbooks.Open Filename:= _
"H:\Cost Centre - Liaison Contact List.xls"

Selection.AutoFilter Field:=7, Criteria1:="<>"

Range("A:A,G:G").Select
Range("G1").Activate
Selection.Copy
Windows("Prepare CSV Files.xls").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Rows("1:2").Select
Range("A2").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("C1").Select

Windows("Cost Centre - Liaison Contact List.xls").Activate
Selection.AutoFilter
Application.EnableEvents = False
ThisWorkbook.Saved = True
ActiveWorkbook.Close savechanges = False
Application.EnableEvents = False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top