NormChart55
New Member
- Joined
- Feb 22, 2022
- Messages
- 42
- Office Version
- 2016
- Platform
- Windows
Hello All,
I have been trying to get this working for quite a bit and no matter what variation I try I always get the Visual basic run time error prompt. I am trying to avoid that as the template I am updating will be used my many people and trying to avoid issues related to that.
Below is the code I am using. its a simple copy/paste into new sheet and saving as a file name. The problem is that when there is already a file at the specified location and a user chooses to hit No or Cancel the run time error occurs. I have tried doing On Error Resume Next but it never passes the save line and current code is below where I am trying to get it to just choose the cell range again if it errors out. I have seen a few posts around this and cannot get any of the code to work when trying to get it into my template. Any thoughts on this are certainly appreciated.
I have been trying to get this working for quite a bit and no matter what variation I try I always get the Visual basic run time error prompt. I am trying to avoid that as the template I am updating will be used my many people and trying to avoid issues related to that.
Below is the code I am using. its a simple copy/paste into new sheet and saving as a file name. The problem is that when there is already a file at the specified location and a user chooses to hit No or Cancel the run time error occurs. I have tried doing On Error Resume Next but it never passes the save line and current code is below where I am trying to get it to just choose the cell range again if it errors out. I have seen a few posts around this and cannot get any of the code to work when trying to get it into my template. Any thoughts on this are certainly appreciated.
VBA Code:
ActiveSheet.Range("A1:F15000").Copy
Set NewBook = Workbooks.Add
NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
ActiveWindow.DisplayGridlines = False
Columns("A:F").Select
Columns("A:F").EntireColumn.AutoFit
Range("A1").Select
On Error GoTo err_handler
ActiveWorkbook.SaveAs Filename:=Path & Filename & " " & dt
err_handler:
Range("A1").Select