Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default File Name Exists Error Trap

I need to stop the file exists from killing my macro and
loop back until my user inputs a filename that is unique.

fname = InputBox("Please Enter File Name", "File Name")
With Application.FileSearch
.Filename = fname
.Execute
If FoundFiles.Count < 0 Then
fname = InputBox("FileName Exists Please Try
Again.", "File Exists")

Else
ActiveWorkbook.SaveAs Filename:=fname
End If

The denotes where I was headed. I am slowly but surely
eating this elephant one bite at a time.

Thanks...

(Hopefully you guys like the taste of Elephant also)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default File Name Exists Error Trap

Hi
you may try

fname = InputBox("Please Enter File Name", "File Name")
With Application.FileSearch
.lookin = "C:\Temp" 'change this
.Filename = fname
If .Execute then
fname = InputBox("FileName Exists Please Try
Again.", "File Exists")
Else
ActiveWorkbook.SaveAs Filename:=fname
End If
--
Regards
Frank Kabel
Frankfurt, Germany

Mike wrote:
I need to stop the file exists from killing my macro and
loop back until my user inputs a filename that is unique.

fname = InputBox("Please Enter File Name", "File Name")
With Application.FileSearch
.Filename = fname
.Execute
If FoundFiles.Count < 0 Then
fname = InputBox("FileName Exists Please Try
Again.", "File Exists")

Else
ActiveWorkbook.SaveAs Filename:=fname
End If

The denotes where I was headed. I am slowly but surely
eating this elephant one bite at a time.

Thanks...

(Hopefully you guys like the taste of Elephant also)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default File Name Exists Error Trap

One way:

fName = Application.InputBox( _
Prompt:="Please enter file name", _
Title:="File name", _
Type:=2)
Do Until Dir(fName) = ""
If fName = "False" Then Exit Sub 'user clicked Cancel
fName = Application.InputBox( _
Prompt:="FileName Exists Please Try Again.", _
Title:="File Exists", _
Type:=2)
Loop
ThisWorkbook.SaveAs Filename:=fName



In article ,
"Mike" wrote:

I need to stop the file exists from killing my macro and
loop back until my user inputs a filename that is unique.

fname = InputBox("Please Enter File Name", "File Name")
With Application.FileSearch
.Filename = fname
.Execute
If FoundFiles.Count < 0 Then
fname = InputBox("FileName Exists Please Try
Again.", "File Exists")

Else
ActiveWorkbook.SaveAs Filename:=fname
End If

The denotes where I was headed. I am slowly but surely
eating this elephant one bite at a time.

Thanks...

(Hopefully you guys like the taste of Elephant also)

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
Error.Type or IsError to trap #VALUE! and #NUM! Ms. AEB Excel Worksheet Functions 1 July 19th 07 06:51 PM
Cleaner Error trap in Loop. plys Excel Discussion (Misc queries) 3 January 20th 07 03:31 AM
Trap a DateValue Error Otto Moehrbach[_6_] Excel Programming 2 February 12th 04 04:51 PM
error trap Rhonda[_3_] Excel Programming 2 October 22nd 03 07:07 PM


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