Hi All,
I have been using the below code for a few years now. It basically saves the tabs of workbook as individual files when a button is pressed.
Since moving to windows 10 the code gets the following error: Run-time error '76': Path not found. It indicates the error happens on "MkDir FolderName"
Does anyone have any idea why its doing this since moving to windows 10?
Thanks in Advance
Tom
I have been using the below code for a few years now. It basically saves the tabs of workbook as individual files when a button is pressed.
Since moving to windows 10 the code gets the following error: Run-time error '76': Path not found. It indicates the error happens on "MkDir FolderName"
Does anyone have any idea why its doing this since moving to windows 10?
VBA Code:
Sub SaveBatches()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FolderName As String
Application.ScreenUpdating = False
Set xWb = Application.ThisWorkbook
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = xWb.Path & "\" & xWb.Name & " " & DateString
MkDir FolderName
ThisPeriod = Application.InputBox("Please Enter Date in the format DD-YY", "Current Date", "DD-YY")
For Each xWs In xWb.Worksheets
xWs.Copy
If Val(Application.Version) < 12 Then
FileExtStr = ".xls": FileFormatNum = -4143
Else
Select Case xWb.FileFormat
Case 51:
FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If Application.ActiveWorkbook.HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56:
FileExtStr = ".xls": FileFormatNum = 56
Case Else:
FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
xFile = FolderName & "\" & "Report Name Report " & ThisDate & " - BATCH" & Application.ActiveWorkbook.Sheets(1).Name & " (" & ActiveWorkbook.Sheets(1).Range("B2").Value & ")" & FileExtStr
Application.ActiveWorkbook.SaveAs xFile, FileFormat:=FileFormatNum
Application.ActiveWorkbook.Close False
Next
MsgBox "You can find the files in " & FolderName
Application.ScreenUpdating = True
End Sub
Thanks in Advance
Tom