Im writing a VBA code to check if a folder exists and if the folder exists just paste the Excel sheet. If the folder doesn't exist create a new folder in run time and save a sheet in that folder.
Code:
If(Len(Dir("C:\Users\Acer\Desktop\Report",vbdirectory))=0 Then
MkDir "C:\Users\Acer\Desktop\Report"
Activeworkbook.saveas filename:="C:\Users\Acer\Desktop\Report\file.xlsx", File format:=51
Else
filename:="C:\Users\Acer\Desktop\Report\file.xlsx", File format:=51
End If
The code works fine for the first time to create a new folder and save the Excel sheet. But on other instances it is not saving the file in the path.
Code:
If(Len(Dir("C:\Users\Acer\Desktop\Report",vbdirectory))=0 Then
MkDir "C:\Users\Acer\Desktop\Report"
Activeworkbook.saveas filename:="C:\Users\Acer\Desktop\Report\file.xlsx", File format:=51
Else
filename:="C:\Users\Acer\Desktop\Report\file.xlsx", File format:=51
End If
The code works fine for the first time to create a new folder and save the Excel sheet. But on other instances it is not saving the file in the path.