MKdir File path Access error 75

m_aatif

Board Regular
Joined
Apr 18, 2013
Messages
56
I am using this code, it executed well with 1st time. However, recurring execution generates MKdir File path Access error 75. Please help how to fix it.


Sub Copy_Every_Sheet_To_New_Workbook()
'Working in 97-2013
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
'Copy every sheet from the workbook with this macro
Set Sourcewb = ThisWorkbook
'Create new folder to save the new files in
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = Sourcewb.Path & "" & Sourcewb.Name & " " & DateString
MkDir FolderName
'Copy every visible sheet to a new workbook
For Each sh In Sourcewb.Worksheets
'If the sheet is visible then copy it to a new workbook
If sh.Visible = -1 Then
sh.Copy
'Set Destwb to the new workbook
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2013
If Sourcewb.Name = .Name Then
MsgBox "Your answer is NO in the security dialog"
GoTo GoToNextSheet
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .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
End If
End With
'Change all cells in the worksheet to values if you want
If Destwb.Sheets(1).ProtectContents = False Then
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
End If

'Save the new workbook and close it
With Destwb
.SaveAs FolderName _
& "" & Destwb.Sheets(1).Name & FileExtStr, _
FileFormat:=FileFormatNum
.Close False
End With
End If
GoToNextSheet:
Next sh
MsgBox "You can find the files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,
You could test to see if directory already exists but the normal trick most apply is to wrap MkDir in an Error trap

Code:
On Error Resume Next
 MkDir FolderName
On Error GoTo 0


Dave
 
Upvote 0
Wrapping it with error does not perform any good. It just misses creating a folder directory. Plz help
 
Upvote 0
Wrapping it with error does not perform any good. It just misses creating a folder directory. Plz help


The solution fixes what you asked for

I am using this code, it executed well with 1st time. However, recurring execution generates MKdir File path Access error 75. Please help how to fix it.


If directory already exists, that line is ignored & your code will continue.

Dave
 
Upvote 0
Then please share with me the code you used. because I have tried a lot. unsuccessful each time..
 
Upvote 0
Then please share with me the code you used. because I have tried a lot. unsuccessful each time..

I provided the code:

Rich (BB code):
    On Error Resume Next
        MkDir FolderName
    On Error GoTo 0

You just place the two lines shown in RED above & below the MkDir line in your code.


Dave
 
Upvote 0
Here is an example of how I use it
Code:
 strPfxDate = Format(Now(), "yyyymmdd")
    strPfxTime = Format(Now(), "hhmmss")
    strFullPath = Left(pstrFile, InStrRev(ActiveWorkbook.FullName, "\"))
    strWBname = Right(pstrFile, Len(pstrFile) - InStrRev(ActiveWorkbook.FullName, "\"))
    strBackupPath = strFullPath & "Backup\"
    ' If backup path does not exist, create it
    If Dir(strBackupPath, vbDirectory) = "" Then
        MkDir strBackupPath
    End If
 
Upvote 0
Let me explain what I want to do.

A file contains multiple sheets. My code extract each sheet in a file and save each of them as a separate file, and names each file as per the sheet name.

When I wrap it, it executes, but does not extract files, rather shows attributes in excel sheet.

Can you please help me in a way that I can perform my objective.

I will be highly obliged
 
Upvote 0
I do not see where you create the new workbook?

I use Workbooks.Add in my code

Code:
    If Dir(strPaymentsPath, vbDirectory) = "" Then
        MkDir strPaymentsPath
    End If


    Application.StatusBar = "Copying required data to new sheet....."
    lLastRow = Range("A" & Rows.Count).End(xlUp).Row
    Range("A1:X" & lLastRow).SpecialCells(xlCellTypeVisible).Copy
    Workbooks.Add
    strNewName = ActiveWorkbook.Name
    With Selection
        .PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
            xlNone, SkipBlanks:=False, Transpose:=False
    End With
 
Upvote 0

Forum statistics

Threads
1,218,208
Messages
6,141,123
Members
450,337
Latest member
bschermerhorn

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
Back
Top