How to save excel file with incrementing number?

前端 未结 2 1431

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:11

    Just put a conditional loop with Dir()

    Do While ((Dir(filepath & tdfilename)) <> Empty)
    inc = inc+1
    filedate = Format(Now, "MMDD") & "." & Format(inc, "00")
    tdfilename = "TD" & filedate & filelist
    Loop
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题