Hi all,
I need help again with my code. I have code but I can't get it to work, it just stops and I am hoping that another set of eyes will see what I missed. SIPPath is my variable for building the file path and Swb is my variable for the full file name. Both are defined as strings and ext is variable as string for file extension ".xlsm".
I use this code to build the daily file path (SIPPath), if it does not exist to the file name, then build the daily filename (Swb) + extension (ext) as we need for daily file system. I need it to check for an existing file name and if it exists then open the file, if the file name does not exist then open the file with that days file name.
All help is welcomed and appreciated.
Private Sub Workbook_Open()
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
On Error GoTo EndItAll:
Application.EnableEvents = False
'Working Code For Sign-In-Workbook Master 10 06 2017
'Check for Year & Month folders Exists, if not Then create
Dim SIPPath As String
Dim Swb As String 'Swb = Daily Sign In Workbook File Name
Dim ext As String 'ext = File name Extension for Excel Macro Enabled File
ext = ".xlsm"
'CHANGE DRIVE LETTER "E" TO "S" TO RUN ON DPS IMPOUND COMPUTERS
SIPPath = "C:\Phoenix XXShared\XX\Sign In Logs\" & Format(Date, "yyyy") & "\"
If Dir(SIPPath, vbDirectory) = "" Then MkDir SIPPath
SIPPath = SIPPath & Format(Date, "MM") & " " & Format(Date, "YYYY") & "\"
If Dir(SIPPath, vbDirectory) = "" Then MkDir SIPPath
Swb = SIPPath & Format(Now, "MM") & "-" & Format(Now, "DD") & "-" & Format(Now, "YYYY") & " Sign-In-Workbook" & ext
If Dir(Swb, vbDirectory) <> "" Then Workbooks.Open (Swb)
Else
'Saves File with Daily Log Name if not found
ActiveWorkbook.SaveAs Filename:=SIPPath & Format(Now, "MM") & "-" & Format(Now, "DD") _
& "-" & Format(Now, "YYYY") & " Sign-In-Workbook", FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
CreateBackup:=False
ActiveWorkbook.Save
If Worksheets("SIGN-IN").Range("B1").Value <= 0 Then Worksheets("SIGN-IN").Range("B1").Value = Date
If Worksheets("CREDIT_CARDS").Range("B4").Value <= 0 Then Worksheets("CREDIT_CARDS").Range("B4").Value = Date
If Worksheets("HP_DEPOSIT").Range("B12").Value <= 0 Then Worksheets("HP_DEPOSIT").Range("B12").Value = Date
If Worksheets("CAP_XX_DEPOSIT").Range("B12").Value <= 0 Then Worksheets("CAP_XX_DEPOSIT").Range("B12").Value = Date
End If
'This will Auto Save Active Workbook every 5 minutes
Application.OnTime Now + TimeValue("00:05:00"), "SaveWb"
End Sub
EndItAll:
Application.EnableEvents = True
End Sub
Bookmarks