Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving According To Abe 1

Status
Not open for further replies.

Fallenwing

Programmer
Aug 8, 2003
13
CA
Okay, this one is more tricky. I want the current Workbook to save in a directory with the next consecutive open number. It references a cell and uses that name. Here is some sample code

' Choosing the Saving Name
' If Name Is Specialty ie. Cornie 09
If Range("PoName").Value > 1000000 Then
President = Range("PoName").Value
' Insert the Referencing Code Here <<--->>
End If
If Range(&quot;Machine&quot;).Value = &quot;Mill&quot; Then ChDir &quot;C:\Miller&quot;
ActiveWorkbook.SaveAs (President)
End Sub

So in the Referencing Code Line I want it to look in the C:\Miller folder for a document already called something that starts with Cornie - like Cornie 01, Cornie 02, and then save this(the PoName) with the next number availible - Cornie 03.

Is this Possible? Any help would be cool.
 
this will give you an idea of the dir function works...



Sub test()
Dim file_name As String
Dim x As Integer
Dim my_path

poname = &quot;cornie&quot;
my_path = &quot;c:\miller&quot; + &quot;\&quot;

file_name = my_path + poname + &quot;*.xls&quot;
f = Dir(file_name)
last_file = Mid(f, Len(poname) + 1, Len(f) - (Len(poname) + 4))
MsgBox (last_file)
MsgBox (f)
Do Until f = &quot;&quot;
f = Dir()
last_file = Mid(f, Len(poname) + 1, Len(f) - (Len(poname) + 4))
MsgBox (f)
MsgBox (last_file)
Loop

End Sub





 
Thanks for all your help. There is one problem though. The time after the sequence finds the highest number it loops through again and on the last_file = Mid(f, Len(poname... line it says Invalid Procedure call or argument.
I ran your code as a standalone Macro. Am I doing something wrong, or is there a simple way to fix this.
PS. Can somebody copy the help file or explain the Mid + Len functions to me? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top