Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default SaveAs no question...

I have a file I save weekly to several different names. I open the
workbook read only and after some modifications. I then copy the
worksheet to a new book. Tell the new workbook it's new name, then
save it to the same location every time. I want to keep the yes / no /
cancel alert for existing workbooks, but would like to get rid of the
saveas dialog completely. In otherwords, if the file doesn't already
exist, save with the filename I've given it.
Been looking though here, but most everyone wants to get rid of the
yes/no/cancel alert...

Anyway, my code example (probably taken from here in the past couple of
years):

Sub sav()
month = Evaluate("IF(MONTH(C4)9,MONTH(C4),0&MONTH(C4))")
day = Evaluate("IF(DAY(C4)9,DAY(C4),0&DAY(C4))")
year = Evaluate("RIGHT(YEAR(C4),2)")
With Application
FN = .GetSaveAsFilename("S:\MYPATH\" & Range("B2").Value & "\"
& Range("B2").Value & " " & month & day & year & ".xls")
If FN < False Then
ActiveWorkbook.ActiveSheet.Buttons.Delete
ActiveWorkbook.SaveAs FN <======== I'd like this to not
show the saveas dialog, just go ahead and save the darn thing with no
questions unless there's an existing workbook.
ActiveWorkbook.Close False
End If
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default SaveAs no question...

See Below
"okrob" wrote in message
ups.com...
I have a file I save weekly to several different names. I open the
workbook read only and after some modifications. I then copy the
worksheet to a new book. Tell the new workbook it's new name, then
save it to the same location every time. I want to keep the yes / no /
cancel alert for existing workbooks, but would like to get rid of the
saveas dialog completely. In otherwords, if the file doesn't already
exist, save with the filename I've given it.
Been looking though here, but most everyone wants to get rid of the
yes/no/cancel alert...

Anyway, my code example (probably taken from here in the past couple of
years):

Sub sav()
month = Evaluate("IF(MONTH(C4)9,MONTH(C4),0&MONTH(C4))")
day = Evaluate("IF(DAY(C4)9,DAY(C4),0&DAY(C4))")
year = Evaluate("RIGHT(YEAR(C4),2)")
With Application
FN = .GetSaveAsFilename("S:\MYPATH\" & Range("B2").Value & "\"
& Range("B2").Value & " " & month & day & year & ".xls")
If FN < False Then
ActiveWorkbook.ActiveSheet.Buttons.Delete
Application.Displayalerts=False
ActiveWorkbook.SaveAs FN <======== I'd like this to not
show the saveas dialog, just go ahead and save the darn thing with no
questions unless there's an existing workbook.
ActiveWorkbook.Close False
End If
End With
Application.Displayalerts=True
End Sub


Corey....


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SaveAs no question...

So you want to stop showing the application.getsaveasfilename?

I _think_ that this does what you want:

Option Explicit
Sub sav()
Dim myDateStr As String
Dim FN As Variant
Dim resp As Long
Dim TestStr As String

With Worksheets(1)
myDateStr = Format(.Range("c4").Value, "mmddyy")
FN = "S:\MYPATH\" & .Range("B2").Value _
& "\" & .Range("B2").Value & " " & myDateStr & ".xls"

TestStr = ""
On Error Resume Next
TestStr = Dir(FN)
On Error GoTo 0

If TestStr = "" Then
'doesn't exist
resp = vbYes
Else
FN = Application.GetSaveAsFilename(InitialFileName:=FN, _
filefilter:="Excel files,*.xls")
If FN = False Then
'do nothing
resp = vbNo
Else
TestStr = ""
On Error Resume Next
TestStr = Dir(FN)
On Error GoTo 0

If TestStr = "" Then
'new chosen name doesn't exist
resp = vbYes
Else
resp _
= MsgBox(Prompt:="Wanna overwrite the existing file", _
Buttons:=vbYesNo)
End If
End If
End If

If resp = vbYes Then
.Buttons.Delete
Application.DisplayAlerts = False
On Error Resume Next
.Parent.SaveAs Filename:=FN, FileFormat:=xlWorkbookNormal
If Err.Number < 0 Then
MsgBox "An error occurred:" _
& vbLf & Err.Number _
& vbLf & Err.Description
Err.Close
Else
'.Parent.Close savechanges:=False
End If
Application.DisplayAlerts = True
Else
MsgBox "Ok, not saved!"
End If
End With
End Sub

You may not want to use variables that are also functions in VBA.

Month(), day() and year() are all VBA functions.

okrob wrote:

I have a file I save weekly to several different names. I open the
workbook read only and after some modifications. I then copy the
worksheet to a new book. Tell the new workbook it's new name, then
save it to the same location every time. I want to keep the yes / no /
cancel alert for existing workbooks, but would like to get rid of the
saveas dialog completely. In otherwords, if the file doesn't already
exist, save with the filename I've given it.
Been looking though here, but most everyone wants to get rid of the
yes/no/cancel alert...

Anyway, my code example (probably taken from here in the past couple of
years):

Sub sav()
month = Evaluate("IF(MONTH(C4)9,MONTH(C4),0&MONTH(C4))")
day = Evaluate("IF(DAY(C4)9,DAY(C4),0&DAY(C4))")
year = Evaluate("RIGHT(YEAR(C4),2)")
With Application
FN = .GetSaveAsFilename("S:\MYPATH\" & Range("B2").Value & "\"
& Range("B2").Value & " " & month & day & year & ".xls")
If FN < False Then
ActiveWorkbook.ActiveSheet.Buttons.Delete
ActiveWorkbook.SaveAs FN <======== I'd like this to not
show the saveas dialog, just go ahead and save the darn thing with no
questions unless there's an existing workbook.
ActiveWorkbook.Close False
End If
End With
End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SaveAs no question...

Activeworkbook.SaveAs FN doesn't show the saveas dialog.
Application.GetSaveAsFilename shows the saveas dialog.




--
Regards,
Tom Ogilvy

"okrob" wrote in message
ups.com...
I have a file I save weekly to several different names. I open the
workbook read only and after some modifications. I then copy the
worksheet to a new book. Tell the new workbook it's new name, then
save it to the same location every time. I want to keep the yes / no /
cancel alert for existing workbooks, but would like to get rid of the
saveas dialog completely. In otherwords, if the file doesn't already
exist, save with the filename I've given it.
Been looking though here, but most everyone wants to get rid of the
yes/no/cancel alert...

Anyway, my code example (probably taken from here in the past couple of
years):

Sub sav()
month = Evaluate("IF(MONTH(C4)9,MONTH(C4),0&MONTH(C4))")
day = Evaluate("IF(DAY(C4)9,DAY(C4),0&DAY(C4))")
year = Evaluate("RIGHT(YEAR(C4),2)")
With Application
FN = .GetSaveAsFilename("S:\MYPATH\" & Range("B2").Value & "\"
& Range("B2").Value & " " & month & day & year & ".xls")
If FN < False Then
ActiveWorkbook.ActiveSheet.Buttons.Delete
ActiveWorkbook.SaveAs FN <======== I'd like this to not
show the saveas dialog, just go ahead and save the darn thing with no
questions unless there's an existing workbook.
ActiveWorkbook.Close False
End If
End With
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default SaveAs no question...

Tom,
Man, I shoulda used some msgboxs to figure this out on my own...
Oh well, nothing like someone pointing out the obvious.
Thanks.
Rob


Tom Ogilvy wrote:
Activeworkbook.SaveAs FN doesn't show the saveas dialog.
Application.GetSaveAsFilename shows the saveas dialog.




--
Regards,
Tom Ogilvy

"okrob" wrote in message
ups.com...
I have a file I save weekly to several different names. I open the
workbook read only and after some modifications. I then copy the
worksheet to a new book. Tell the new workbook it's new name, then
save it to the same location every time. I want to keep the yes / no /
cancel alert for existing workbooks, but would like to get rid of the
saveas dialog completely. In otherwords, if the file doesn't already
exist, save with the filename I've given it.
Been looking though here, but most everyone wants to get rid of the
yes/no/cancel alert...

Anyway, my code example (probably taken from here in the past couple of
years):

Sub sav()
month = Evaluate("IF(MONTH(C4)9,MONTH(C4),0&MONTH(C4))")
day = Evaluate("IF(DAY(C4)9,DAY(C4),0&DAY(C4))")
year = Evaluate("RIGHT(YEAR(C4),2)")
With Application
FN = .GetSaveAsFilename("S:\MYPATH\" & Range("B2").Value & "\"
& Range("B2").Value & " " & month & day & year & ".xls")
If FN < False Then
ActiveWorkbook.ActiveSheet.Buttons.Delete
ActiveWorkbook.SaveAs FN <======== I'd like this to not
show the saveas dialog, just go ahead and save the darn thing with no
questions unless there's an existing workbook.
ActiveWorkbook.Close False
End If
End With
End Sub




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
Saveas VBA question Lost Excel Discussion (Misc queries) 1 June 2nd 09 07:51 AM
SaveAs Question Rob Excel Programming 2 September 10th 06 09:15 PM
Another SaveAs Question chipshot[_2_] Excel Programming 7 April 7th 06 06:58 PM
SaveAs Question Greg Little Excel Programming 3 December 7th 04 02:37 AM
Question Using SaveAs Method R3df1sh Excel Programming 1 November 12th 03 07:26 PM


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