Hello,
can someone help me with suppressing the "saving as \\xyz\branch\sh\Analyst Use Only\UserLog.xls" dialog box that appears when saving?
I have attempted to add Application.DisplayAlerts=FALSE and Application.DisplayAlerts=True to the code but it doesn't seem to make any difference. Thank you.
can someone help me with suppressing the "saving as \\xyz\branch\sh\Analyst Use Only\UserLog.xls" dialog box that appears when saving?
I have attempted to add Application.DisplayAlerts=FALSE and Application.DisplayAlerts=True to the code but it doesn't seem to make any difference. Thank you.
VBA Code:
'Create UserLog and record metrics
Dim filePath As String
Dim wb As Workbook
Dim ws As Worksheet
Dim lastRow As Long
Application.ScreenUpdating = False
' Define the file path
filePath = "\\xyz\branch\sh\Analyst Use Only\UserLog.xlsx"
' Check if the file exists
If Dir(filePath) = "" Then
' Create a new workbook if the file doesn't exist
Set wb = Workbooks.Add
wb.SaveAs filePath
wb.Close
End If
' Open the UserLog workbook
Set wb = Workbooks.Open(filePath)
' Add a new worksheet named "UserLog" if it doesn't exist
On Error Resume Next
Set ws = wb.Sheets("UserLog")
On Error GoTo 0
If ws Is Nothing Then
Set ws = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count))
ws.Name = "UserLog"
' Add headers
With ws
.Cells(1, 1) = "Username"
.Cells(1, 2) = "Date and Time"
End With
End If
' Find the last used row in column A
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' Unprotect sheet and write username and current date and time to the next row
With ws
.Unprotect "incorrect"
.Cells(lastRow + 1, 1) = Environ("Username")
.Cells(lastRow + 1, 2) = Now
End With
' Autofit all columns
ws.Columns.AutoFit
'Re-protect sheet
ws.Protect "incorrect", UserInterfaceOnly:=True
' Save the workbook
wb.Save
' Close the workbook
wb.Close
Application.ScreenUpdating = True
' Release memory
Set wb = Nothing
Set ws = Nothing
Application.ScreenUpdating = True
'Process Complete messaging
MsgBox "Process Complete."