craig schultz
New Member
- Joined
- Dec 4, 2014
- Messages
- 47
Hi, I wonder if anyone could help me please.
I have a code below which saves the excel file as a copy to its current location and renames the file 'customer copy'
This works fine the first time, but when a file with the same name exists in the current location and I chose the option 'No' or 'Cancel' I get a run-time error.
I'm sure its a simple fix but I am fairly new to VBA and would really appreciate any help.
Sub Customercopy()
ActiveSheet.Unprotect
' Copy activesheet to the new workbook
ActiveSheet.Copy
Columns("H:J").Select
Selection.Delete Shift:=xlToLeft
Cells.Validation.Delete
Dim btn As Shape
For Each btn In ActiveSheet.Shapes
If btn.AutoShapeType = msoShapeStyleMixed Then btn.Delete
Next
'Save new workbook as MyWb.xls(x) into the folder where ThisWorkbook is stored
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Proprietary Equipment Bom Customer Copy", FileFormat:=xlOpenXMLWorkbookMacroEnabled
MsgBox "Bom has been saved with 'Denco Reference Only' Columns and All Previous Revisions Removed. Saved in Current Bom File " & ActiveWorkbook.FullName & vbLf & "Press OK to close it"
' Close the saved copy
ActiveWorkbook.Close False
ActiveSheet.Protect
End Sub
Many thanks
Craig
I have a code below which saves the excel file as a copy to its current location and renames the file 'customer copy'
This works fine the first time, but when a file with the same name exists in the current location and I chose the option 'No' or 'Cancel' I get a run-time error.
I'm sure its a simple fix but I am fairly new to VBA and would really appreciate any help.
Sub Customercopy()
ActiveSheet.Unprotect
' Copy activesheet to the new workbook
ActiveSheet.Copy
Columns("H:J").Select
Selection.Delete Shift:=xlToLeft
Cells.Validation.Delete
Dim btn As Shape
For Each btn In ActiveSheet.Shapes
If btn.AutoShapeType = msoShapeStyleMixed Then btn.Delete
Next
'Save new workbook as MyWb.xls(x) into the folder where ThisWorkbook is stored
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Proprietary Equipment Bom Customer Copy", FileFormat:=xlOpenXMLWorkbookMacroEnabled
MsgBox "Bom has been saved with 'Denco Reference Only' Columns and All Previous Revisions Removed. Saved in Current Bom File " & ActiveWorkbook.FullName & vbLf & "Press OK to close it"
' Close the saved copy
ActiveWorkbook.Close False
ActiveSheet.Protect
End Sub
Many thanks
Craig