I have the following code the personal.xlsb file on my desktop computer running Excel 2010 under Windows 10:
The code sets the title bar to display the full file path whenever a file is opened or saved. The code works fine on my desktop computer, but when I copy the file to the following location on my laptop (also running Excel 2010 under Windows 10):
and then try to open an excel file, I get the following error:
In reference to the following line inside the
How do I fix error, and why I am I only seeing it on my laptop when both computers are running the same OS and Excel versions?
VBA Code:
Option Explicit
' code to automatically display the full file path in the Excel title bar
' copied from here: https://www.mrexcel.com/board/threads/possible-to-always-display-full-file-path-in-title-bar-excel-2010.1206961/#post-5895948
' test comment
' might need to mark this file as 'read only' to avoid getting "open for editing" errors when opening multiple instances of Excel: https://www.systemroot.ca/2013/08/how-to-fix-file-in-use-personal-xlsb-is-locked-for-editing/
Private WithEvents xlsApp As Application
' shouldn't need to use ThisWorkbook.Application; Application should work fine
' from: https://www.mrexcel.com/board/threads/how-to-update-title-bar-to-display-full-file-path-when-document-is-saved.1211738/#post-5920546
Private Sub Workbook_Open()
Set xlsApp = Application
End Sub
Private Sub xlsApp_WorkbookOpen(ByVal Wb As Workbook)
ActiveWindow.Caption = Wb.FullName
End Sub
' new code to have the title bar updated whenever the document is saved; this ensures newly-created documents will have their paths displayed
' in the title bar once they are saved
' note it is not necessary to include this functionality in both the WorkbookBeforeSave and WorkbookAfterSave events; I was just copying the
' code from a reply to my thread here: https://www.mrexcel.com/board/threads/how-to-update-title-bar-to-display-full-file-path-when-document-is-saved.1211738/#post-5920546
Private Sub xlsApp_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
Debug.Print Wb.FullName
ActiveWindow.Caption = Wb.FullName
End Sub
Private Sub xlsApp_WorkbookAfterSave(ByVal Wb As Workbook, ByVal Success As Boolean)
Debug.Print Wb.FullName
ActiveWindow.Caption = Wb.FullName
End Sub
The code sets the title bar to display the full file path whenever a file is opened or saved. The code works fine on my desktop computer, but when I copy the file to the following location on my laptop (also running Excel 2010 under Windows 10):
VBA Code:
C:\Users\Special_K\AppData\Roaming\Microsoft\Excel\XLSTART\personal.xlsb
and then try to open an excel file, I get the following error:
Run-time error '91':
Object variable or With block variable not set
In reference to the following line inside the
xlsApp_WorkbookOpen(ByVal Wb As Workbook)
subroutine:ActiveWindow.Caption = Wb.FullName
How do I fix error, and why I am I only seeing it on my laptop when both computers are running the same OS and Excel versions?