Error Message Since Moving to Windows 10

tomexcel1

New Member
Joined
Feb 22, 2018
Messages
45
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?

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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
568
Office Version
  1. 365
Platform
  1. Windows
Are you by any chance running it on OneDrive or Sharepoint ?
Worked fine for me on my C Drive but crashed on OneDrive.
 

tomexcel1

New Member
Joined
Feb 22, 2018
Messages
45
Hi Alex,

Yes that might be it, it normally is saved on the desktop but windows 10 desktop is on OneDrive. Can you think of a way of fixing it?

Thanks
Tom
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,916
Office Version
  1. 365
Platform
  1. Windows
You cannot run macros/vba on OneDrive. OneDrive does not support VBA.
You can store files with VBA code on OneDrive, but if you want to run the code, you will need to download the file to your computer first.
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,916
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
Glad we were able to help.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,515
Messages
5,636,793
Members
416,941
Latest member
shazzaxyz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top