How to save excel file with incrementing number?

前端 未结 2 1430

I am looking for VBA to add to my macro that will increment the file name if the file name already exists.

Current Code:

Dim filepath As String
Dim          


        
2条回答
  •  灰色年华
    2021-01-07 15:12

    Someone suggested this and it worked for me:

    Dim filecount As Integer
    
    Do While Len(Dir(filepatharch & thfilename)) <> 0
            filecount = filecount + 1
            filedate = Format(Now, "MMDD0" & filecount & ".")
            tdfilename = "TD" & filedate & filelist
            thfilename = "TH" & filedate & filelist
    Loop
    

提交回复
热议问题