Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default getsaveasfilename loop... < false and not already exists

I would like to know if there is a way to turn this:

Sub saveas()
Workbooks.Open Filename:= _
"C:\Toxo QNS temp.xls"
Do
fname = Application.GetSaveAsFilename("Save as dayToxoQNS", _
fileFilter:="Excel Files
(*.xls), *.xls")
Loop Until fname < False
If Dir(fname) < "" Then
MsgBox "You can't overwrite an existing file try again"
Windows("Toxo QNS temp.xls").Close
Call saveas

into a working version of this:

Workbooks.Open Filename:= _
"C:\Toxo QNS temp.xls"
Do
fname = Application.GetSaveAsFilename("Save as dayToxoQNS", _
fileFilter:="Excel Files
(*.xls), *.xls")
Loop Until (fname < False) And (Dir(fname) Is "")

The second code gives a type mismatch at the "(Dir(fname) Is "")"

The goal being to stop accidental overwrites and not have to restart
the macro to do it, so that i can drop the altered loop until snippet
into all of the places it would be good to have. If there isnt a handy
way to do it, I am fine with that i would just like to know so i stop
trying to figure it out. Thank you in advance for any responses

john
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default getsaveasfilename loop... < false and not already exists

Try this code

Sub saveas()

Workbooks.Open Filename:= _
"C:\Toxo QNS temp.xls"
Do
fname = Application.GetSaveAsFilename("Save as dayToxoQNS", _
fileFilter:="Excel Files(*.xls), *.xls")

If fname < False Then
If Dir(fname) < "" Then
MsgBox "You can't overwrite an existing file try again"
fname = False
End If
End If
Loop Until fname < False

Windows("Toxo QNS temp.xls").Close
Call saveas

End Sub


"goaljohnbill" wrote:

I would like to know if there is a way to turn this:

Sub saveas()
Workbooks.Open Filename:= _
"C:\Toxo QNS temp.xls"
Do
fname = Application.GetSaveAsFilename("Save as dayToxoQNS", _
fileFilter:="Excel Files
(*.xls), *.xls")
Loop Until fname < False
If Dir(fname) < "" Then
MsgBox "You can't overwrite an existing file try again"
Windows("Toxo QNS temp.xls").Close
Call saveas

into a working version of this:

Workbooks.Open Filename:= _
"C:\Toxo QNS temp.xls"
Do
fname = Application.GetSaveAsFilename("Save as dayToxoQNS", _
fileFilter:="Excel Files
(*.xls), *.xls")
Loop Until (fname < False) And (Dir(fname) Is "")

The second code gives a type mismatch at the "(Dir(fname) Is "")"

The goal being to stop accidental overwrites and not have to restart
the macro to do it, so that i can drop the altered loop until snippet
into all of the places it would be good to have. If there isnt a handy
way to do it, I am fine with that i would just like to know so i stop
trying to figure it out. Thank you in advance for any responses

john

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default getsaveasfilename loop... < false and not already exists

Worked great! thanks. It never occured to me to put ifs inside the do
loop. Everytime I learn 1 thing i end up wondering how to do 3 more.
I did take out the msgbox, temp close and call since that was the
stuff i wanted to do away with to begin with. The if part will go very
easily into other Do getsaveasfilename loops to give the same
functionality.

Thanks again
john
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
VBA - Do Loop or SaveChanges = false Dan Excel Discussion (Misc queries) 1 January 23rd 09 05:54 PM
VBA always creates linked chart even when using PasteExcelTable False, False, False in Office 2007 Matt Simpson Excel Programming 0 August 6th 07 08:11 PM
need array of true/false if text exists alex Excel Worksheet Functions 0 November 16th 04 09:58 AM
Loop until a condition is False matt_steer[_3_] Excel Programming 1 May 18th 04 03:41 PM
True Or False, no matter what... it still displays the false statement rocky640[_2_] Excel Programming 2 May 13th 04 04:57 PM


All times are GMT +1. The time now is 06:10 PM.

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

About Us

"It's about Microsoft Excel"