LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Check if filename exists.

Hi Dave,

Good question. It compiled, however I didn't try to run it (I should have).
The following variation however will run...

Dim strValue As String
strValue = "P:\Folder\" & Worksheets("GEMFEDCCOrderForm").Range("F9").Value
MyFile = Dir(strValue & ".xls")
' more similar stuff...

Thank for pointing that out.

Jim Cone
San Francisco, USA


"Dave Peterson" wrote in message
...
Did this work for you:
With "P:\Folder\" & Worksheets("GEMFEDCCOrderForm").Range("F9")



Jim Cone wrote:


Darrin,
On the other hand, if you just want to clean up and
simply your code then see the following...
'-------------------------------------------------
Sub SimplifiedCode()
'Jim Cone - San Francisco, USA - May 05, 2005

Dim MyFile As String
Dim MyFile1 As String
Dim MyFile2 As String
Dim MyFile3 As String
Dim MyFile4 As String
Dim MyFile5 As String

With "P:\Folder\" & Worksheets("GEMFEDCCOrderForm").Range("F9")
MyFile = Dir(.Value & ".xls")
MyFile1 = Dir(.Value & "-1.xls")
MyFile2 = Dir(.Value & "-2.xls")
MyFile3 = Dir(.Value & "-3.xls")
MyFile4 = Dir(.Value & "-4.xls")
MyFile5 = Dir(.Value & "-5.xls")
End With

With Worksheets("Sheet1").Range("F9")
If MyFile4 = .Value & "-4.xls" Then
ActiveWorkbook.SaveAs Filename:="P:\Folder\" & .Value & "-5.xls"
ElseIf MyFile3 = .Value & "-3.xls" Then
ActiveWorkbook.SaveAs Filename:="P:\Folder\" & .Value & "-4.xls"
ElseIf MyFile2 = .Value & "-2.xls" Then
ActiveWorkbook.SaveAs Filename:="P:\Folder\" & .Value & "-3.xls"
ElseIf MyFile1 = .Value & "-1.xls" Then
ActiveWorkbook.SaveAs Filename:="P:\Folder\" & .Value & "-2.xls"
ElseIf MyFile = .Value & ".xls" Then
ActiveWorkbook.SaveAs Filename:="P:\Folder\" & .Value & "-1.xls"
ElseIf MyFile = "" Then
ActiveWorkbook.SaveAs Filename:="P:\Folder\" & .Value & ".xls"
End If
End With
End Sub
'----------------------------------------


-snip-
 
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
check if sheet exists mohavv Excel Discussion (Misc queries) 1 November 21st 07 01:58 AM
check if worksheet exists joeeng Excel Worksheet Functions 3 September 7th 05 06:49 PM
check to see if sheet exists Wandering Mage Excel Programming 1 September 28th 04 07:53 PM
Check to see if sheet exists Steph[_3_] Excel Programming 4 September 22nd 04 12:47 AM
check if worksheet exists Craig Wilks Excel Programming 2 July 10th 03 04:07 AM


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