saving text file..file name ref numbering from current files

dantheman9

Board Regular
Joined
Feb 5, 2011
Messages
175
Hi Im trying to add a hidden section to saving a file to a folder to all a three digit number to the start of the file name...however, I need to be able to set this number by looking in the folder selected, read each number from other files then set the new file number in the next in sequance.

eg.

the folder might have;
001 filename 1
002 another name2
003 another file name
004 file

what I would need is to be albe to set the next number to 005

Im using the following for saving;


Code:
Dim rng As Range
Dim wb As Workbook
Dim Fname As Variant
[COLOR=red]Dim filenumber As Long    ' need to be able to set this from looking at other files
[/COLOR]Set rng = Range("A1:A211")
Set wb = Workbooks.Add
With wb
rng.Copy
.Worksheets(1).Range("A1").PasteSpecial Paste:=xlValues
ChDir (Path)   ' open path as set in path option box
Application.DisplayAlerts = False
' set file name from textbox 1 (default is enter file name
Fname = Application.GetSaveAsFilename( _
InitialFileName:= [COLOR=red]filenumber[/COLOR] & " - " & TextBox1, _
filefilter:="text file, *.txt", _
Title:="Save Race File To...")
If Fname <> False Then
.SaveAs Fname, xlTextMSDOS
End If
.Close False
Application.DisplayAlerts = True
End With
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top