LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Original read only file not closing

Hello there,
I need to Save As only the visible files from a read only file. When I added
the code to select only visible sheets, the original read only file doesn't
close and it is asking if I want to save the changes (?).
Can anybody please point me to the right direction... How can I make the
read only file to close when the new one is saved?
Thanks so much
Gaba

Private Sub CommandSaveAs_Click()
Unload frmMainMenu
Sheets("Menu").Visible = False
'do not copy menu sheet

Dim NameAk As String
Dim NewName As Variant
Dim myfile As String

Dim bk As Workbook
Dim sh As Worksheet, bReplace As Boolean
Dim sh1 As Worksheet
Set sh1 = ActiveSheet
bReplace = True

For Each sh In Worksheets
If sh.Visible = True Then
sh.Select Replace:=bReplace
bReplace = False
End If
Next
ActiveWindow.SelectedSheets.Copy
Set bk = ActiveWorkbook
Worksheets(1).Select
sh1.Parent.Activate
sh1.Select
bk.Activate

myfile = "Temp"

NameAk = ActiveSheet.Name & myfilename & ".xls"
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\Temp\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")

If NewName < False Then
If Dir(NewName) < "" Then
Select Case MsgBox("File Exists. Overwrite ?", vbYesNoCancel +
vbQuestion)
Case vbYes
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=NewName,
FileFormat:=xlWorkbookNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
Case vbNo
Do
NewName = Application.GetSaveAsFilename( _
InitialFileName:=ActiveWorkbook.Path & "\Temp\" & _
NameAk, FileFilter:="Excel Workbooks (*.xls), *.xls")
If NewName = False Then Exit Sub
Loop Until Dir(NewName) = ""
ActiveWorkbook.SaveAs FileName:=NewName,
FileFormat:=xlWorkbookNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

Case Else
Exit Sub
End Select
Else
ActiveWorkbook.SaveAs FileName:=NewName,
FileFormat:=xlWorkbookNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

End If
End If

End Sub


 
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
SaveAs without closing original workbook Stefi Excel Programming 6 December 14th 07 07:25 AM
how can i read data from a closing excel file? GF[_3_] Excel Programming 2 November 26th 06 07:33 PM
File Says Read Only Even After Closing It Dileep Chandran Excel Discussion (Misc queries) 3 October 31st 06 07:01 PM
Auto save replaced my original file and now I need the original? Hols Excel Discussion (Misc queries) 1 August 15th 05 10:34 PM
Copy file and closing original Rob Excel Programming 3 May 8th 04 01:37 PM


All times are GMT +1. The time now is 11:48 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"