Hi
I have this save button, that saves:
My problem is if i want to save the sheets again it dosn't overwrite the old one.
So my question is how to change the code so it overwrite existing files if necessary?
Here is my code
I have this save button, that saves:
- 3 sheets into pdf
- 4 sheets into a new workbook (xlsm)
- 1 sheet into a new copy inside the workbook
My problem is if i want to save the sheets again it dosn't overwrite the old one.
So my question is how to change the code so it overwrite existing files if necessary?
Here is my code
Code:
Sub Gemsom()
Dim fName As String
With Worksheets("Prisliste")
fName = ThisWorkbook.Worksheets("Prisliste").Range("D1").Value & ThisWorkbook.Worksheets("Prisliste").Range("E10").Value & ThisWorkbook.Worksheets("Prisliste").Range("D4").Value
End With
Worksheets("Tilbud").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\rasmu\Desktop\2019\Tilbud\" & fName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Worksheets("Lejekontrakt").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\rasmu\Desktop\2019\Lejekontrakt\" & fName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Worksheets("Faktura").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\rasmu\Desktop\2019\Faktura\" & fName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Sheets(Array("Prisliste", "Tilbud", "Lejekontrakt", "Faktura")).Copy
'there is now a new active workbook
With ActiveWorkbook
'save it
.SaveAs Filename:= _
"C:\Users\rasmu\Desktop\2019\" & ThisWorkbook.Worksheets("Prisliste").Range("D1").Value & ThisWorkbook.Worksheets("Prisliste").Range("E10").Value & ThisWorkbook.Worksheets("Prisliste").Range("D4").Value, FileFormat:=52
'optionally close it
.Close savechanges:=True
End With
End Sub