Windows(ThisWorkbook.Name).Visible = True导致Excel的自动恢复文件错误 [英] Windows(ThisWorkbook.Name).Visible = True causes error on Excel's auto-recovered files

查看:726
本文介绍了Windows(ThisWorkbook.Name).Visible = True导致Excel的自动恢复文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2个月前我问过这个问题:
宏启用Excel文件上的自动保存的文件错误

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

感谢@ YowE3K,当我尝试恢复时,他引用了Workbook_Open事件,因为问题出现-open)文件。今天我深深地关注它,发现我得到的原因:

Thanks to @YowE3K he referred me to Workbook_Open event as the problem was occurring when I try to recover(re-open) the file. Today I deeply focused on it and found that the reason I was getting:

 Run-time error '9'

 Subscript out of range

错误是:

Windows(ThisWorkbook.Name).Visible = True

我不知道如何当我尝试打开自动恢复文件时,我意识到文件正常打开,我的表单正常打开,但是当窗体消失时,错误通过,文件的名称更改为Microsoft Excel,一切消失从屏幕,所有的Excel功能区冻结,我只能去开发人员选项卡,没有任何改变的情况。

I don't know how it became False but, when I try to open auto-recover file, I realize that file is opening normally, my form is opening normally, but when form disappears, the error comes through, the name of the file changes to Microsoft Excel, everything disappear from screen, all of the Excel ribbon freeze, I can only go to Developer tab, nothing changes the situation.

所以我认为,excel不知何故不能转Windows (ThisWorkbook.Name)。表单(我的Excel Splash Screen)消失后,可以为True。

So I think that,excel somehow can't turn Windows(ThisWorkbook.Name).Visible to True after Form (my Excel Splash Screen) disappears.

我该如何避免?我不想删除我的幻想闪屏,但我有时也需要使用自动恢复文件。

How can I avoid this? I don't want to delete my fancy splash screen but I sometimes need to use auto-recover files as well.

微软页面的类似问题

XL2003:更改ThisWorkbook.Windows()。Workbook_BeforeClose事件中的可见属性阻止工作簿关闭
根本不帮助我。

Similar issue from Microsoft's page and XL2003: Changing ThisWorkbook.Windows().Visible property during Workbook_BeforeClose event prevents workbook from closing are not helping me at all.

推荐答案

代码失败,因为当Excel恢复文件时,它会向窗口的标题添加一些文本,因此FileName.xlsx会变成FileName.xlsx [Version最后由用户保存]。
所以使用一个例程:

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

这篇关于Windows(ThisWorkbook.Name).Visible = True导致Excel的自动恢复文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆