automatic file name

  • Thread starter Thread starter bratek
  • Start date Start date
B

bratek

Hi

I have one problem with excel:
my data are beeing colected real time and from time to time I want to
backup them. I made such thing:


Dim ff as Integer
ff = FileFree()
Lastrecord = 1000
FirstCol = 1
LastCol = 5

Open "C:\arch\backup.txt" For Append as ff
for r = 5 to Lastrecord
for C = FirstCol To LastCol
if C=1 Then
Print #ff, Format(Cells(r,C), "yyyy-mm-dd") &
vbTab;
Elseif C = 2 Then
Print #ff, Format(Cells(r,C), "hh:mm:ss") & vbTab;
Else
Print #ff, Cells(r,C) & vbTab;
End if
Next C
Print #ff;
Next r
Close ff


The only thing is how to force excel that each time Export procudure is
call the name of the file (backup.txt) different?! :)
thanks for help ;)
 
You shouldn't because you are Appending to the same file.
If you mean you want to create a new file each time then keep a counter on
the sheet, Range("BackUpCount") and increment each time.

Range("BackUpCount").Value=Range("BackUpCount").Value+1
Open "C:\arch\backup" & Range("BackUpCount").Value & ".txt" For Output as ff

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top