dantheman9
Board Regular
- Joined
- Feb 5, 2011
- Messages
- 175
Hi I have some files that need to saved in number order with a three number string eg 001, 002, 003 etc.
two questions, in the code below (in the loop) how can i increment the string number by one each time?
secondly, you will see Im using the getsaveasfilename, if there a method to add this number after that option (if so the user cannot remove this part of the file name?
two questions, in the code below (in the loop) how can i increment the string number by one each time?
secondly, you will see Im using the getsaveasfilename, if there a method to add this number after that option (if so the user cannot remove this part of the file name?
Code:
Dim rng As Range
Dim wb As Workbook
Dim Fname As Variant
Dim filenumber As Variant
Set rng = Range("A1:A211")
Set wb = Workbooks.Add
filenumber = "001"
[COLOR=red]If Len(Dir(Path & filenumber & "*")) > 0 Then
Do While Len(Dir(Path & filenumber & "*")) > 0
filenumber = filenumber + 1
Loop
[/COLOR]End If
With wb
rng.Copy
.Worksheets(1).Range("A1").PasteSpecial Paste:=xlValues
' open path as set in path option box
ChDir (Path)
Application.DisplayAlerts = False
' set file name from textbox 1 (default is enter file name
Fname = Application.GetSaveAsFilename( _
[COLOR=red]InitialFileName:=filenumber & " - " & TextBox1,[/COLOR] _
[COLOR=red]' can i add the filenumber after this so the user cannot mod it?
[/COLOR]filefilter:="Text File, *.txt", _
Title:="Save File To...")
If Fname <> False Then
.SaveAs Fname, xlTextMSDOS
End If
.Close False