Windows(ThisWorkbook.Name).Visible = True causes error on Excel's auto-recovered files

后端 未结 3 1065
故里飘歌
故里飘歌 2021-01-22 07:57

2 months ago I\'ve asked this question: Autosaved file error on Macro Enabled Excel file

Thanks to @YowE3K he referred me to Workbook_Open event as the problem was occur

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 08:48

    The code fails because when Excel recovers a file, it adds some text to the caption of the window, so that "FileName.xlsx" becomes something like "FileName.xlsx [Version last saved by user]". So use a routine like:

    Sub ShowaWindow(sFileName As String)
        Dim oWb as Workbook
        For Each oWb In Workbooks
            If lCase(owb.Name) = lCase(sFileName) Then
                oWb.Windows(1).Visible = True
                Exit For
            End If
        Next
    End Sub
    

提交回复
热议问题