Excel VBA Check if directory exists error

后端 未结 7 986
别那么骄傲
别那么骄傲 2020-12-01 10:34

I have a spreadsheet that upon clicking a button will duplicate itself by copying/pasting everything to a new workbook and save the file with a name that is dependent upon s

7条回答
  •  悲哀的现实
    2020-12-01 10:52

    You can replace WB_parentfolder with something like "C:\". For me WB_parentfolder is grabbing the location of the current workbook. file_des_folder is the new folder i want. This goes through and creates as many folders as you need.

            folder1 = Left(file_des_folder, InStr(Len(WB_parentfolder) + 1, file_loc, "\"))
            Do While folder1 <> file_des_folder
                folder1 = Left(file_des_folder, InStr(Len(folder1) + 1, file_loc, "\"))
                If Dir(file_des_folder, vbDirectory) = "" Then      'create folder if there is not one
                    MkDir folder1
                End If
            Loop
    

提交回复
热议问题