aggiemarine07
New Member
- Joined
- Nov 5, 2013
- Messages
- 46
Ok so I am running into a problem with using the below code since I started storing it on OneDrive. Basically, what the code is supposed to do is copy the existing worksheet to a new workbook and then save the workbook; prior to this though it is supposed to delete any previous/existing version of the file prior to creating the new workbook. My problem is that the code errors out on the
line of the code
I apologize in advance if this is a duplicate and/or has been answered elsewhere but I have searched Google and other forums but have not found a good answer, so maybe I am searching with the wrong keywords. Thanks!
VBA Code:
If Len(Dir$(strFile)) > 0 Then Kill strFile
VBA Code:
Sub Macro1()
mypath = Application.ActiveWorkbook.Path
'delete previous weeks sheet
Dim strFile As String: strFile = Application.ActiveWorkbook.Path & "\" & Mid(FileOnly, 1, InStr(FileOnly, ".") - 1) & " " & Format(Date - 7, "YYYY.MM.DD") & ".xlsb"
If Len(Dir$(strFile)) > 0 Then Kill strFile
ThisWorkbook.Sheets("Allocations").Copy
ActiveWorkbook.SaveAs mypath & "\" & Mid(FileOnly, 1, InStr(FileOnly, ".") - 1) & " " & Format(Date, "YYYY.MM.DD") & ".xlsb", FileFormat:=50
End Sub
I apologize in advance if this is a duplicate and/or has been answered elsewhere but I have searched Google and other forums but have not found a good answer, so maybe I am searching with the wrong keywords. Thanks!