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