Error Handling for the mkdir command

Smurphster16

New Member
Joined
Feb 28, 2019
Messages
25
Hi,

I have written some code which saves down a particular sheet of my excel workbook in excel and PDF form.

I use the mkdir to create a new directory for the files to be saved in - however I need to insert some error handling into my code so that if I have already run the code and created the directory and saved the files - I do not get an error message (i do at the moment If i have already run the Macro and the directory has already been created)

What I want to happen is that the new files are saved down to the correct directory that already exists and a prompt is received to override the existing files.

The code is pasted below.

Many thanks for your help

Code:
Dim ws1 As Worksheet
Dim mydir, Fname As String
Dim Answer As Integer




CID2 = Sheets("Liquidity_input").Range("CID").Value
SEC_ID2 = Sheets("Liquidity_input").Range("SEC_ID").Value


MkDir "W:\Data Management\D - Data Management Tool\1_Data_Audit" & "\" & CID2
MkDir "W:\Data Management\D - Data Management Tool\1_Data_Audit" & "\" & CID2 & "\" & SEC_ID2


mydir = "W:\Data Management\D - Data Management Tool\1_Data_Audit" & "\" & CID2 & "\" & SEC_ID2


Application.CopyObjectsWithCells = True


Fname = Sheets("Liquidity_Input").Range("sec_id").Value


Sheets("Liquidity_Input").Copy
For Each ws1 In ActiveWorkbook.Worksheets
    With ws1.UsedRange
        .Value = .Value
    End With
Next ws1
With ActiveWorkbook
    .SaveAs Filename:=mydir & "\" & Fname
    .Close
End With


With Sheets("lIQUIDITY_INPUT")
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=mydir & "\" & Fname _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False
End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
hi

maybe this

Rich (BB code):
On Error Resume Next
    MkDir "W:\Data Management\D - Data Management Tool\1_Data_Audit" & "\" & CID2
    MkDir "W:\Data Management\D - Data Management Tool\1_Data_Audit" & "\" & CID2 & "\" & SEC_ID2
On Error GoTo 0

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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