启用编辑后,范围(" My_Name")失败

时间:2016-09-06 20:55:08

标签: excel-vba vba excel

我有一个启用了Macro的电子表格。 在The ThisWorkbook'区域我有例程来检查用户可以点击的位置。 以下是代码的摘录:

Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)

Dim WhichNumbers As String
Dim WhichData As String
Dim WhichStatuses As String
Dim ToAddress As String
Dim CCAddress As String
Dim sFound As String
Dim wsTemp As Workbook
Dim sThisQuoteNumber As String
Dim pdfShell As Object

If sh.Name = "Report" Then
' If we intersect with one of the Quote Numbers, then present him with a view of the PDF of the quote.
If Not Intersect(Target, Range("QuoteNumber")) Is Nothing And (Selection.Count = 1) Then
    iRow = Target.Row
 .....

以下是发生的事情: 这段代码一切正常。 我将文件通过电子邮件发送给另一个用户,当他在电子邮件中打开它时,或者如果他将其保存在他的驱动器上并打开它,文件看起来很好,但是顶部的消息说你必须启用编辑。 当您点击“启用”按钮时按钮,程序停止,并显示一个错误,指示Range(" QuoteNumber")方法失败。 消息框允许您结束"或"调试"。 如果您点击结束',则会清除消息框,此时程序正常运行。

知道发生了什么事吗?如何阻止这种情况发生,因此它不会爆炸?如果我的用户'面?

1 个答案:

答案 0 :(得分:0)

为了确保您定义了命名范围" QuoteNumber "作为工作簿范围,对吗?此外," QuoteNumber "范围在此WorkBook中。

我定义了" QuoteNumber "作为WorkBook范围,它的范围在" Repot " Sheet,我使用了Range(A1:C10)。 当我通过电子邮件发送这个工作簿(附上下面的代码)和我的同事(在他的电脑上)点击范围内的一个单元格(A1:C10)" 报告&#34 ;表格(单元格B3),他得到了我的测试MsgBox"行号为3"。

Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)

Dim WhichNumbers As String
Dim WhichData As String
Dim WhichStatuses As String
Dim ToAddress As String
Dim CCAddress As String
Dim sFound As String
Dim wsTemp As Workbook
Dim sThisQuoteNumber As String
Dim pdfShell As Object

If sh.Name = "Report" Then
    ' If we intersect with one of the Quote Numbers, then present him with a view of the PDF of the quote.
    If Not Intersect(Target, Range("QuoteNumber")) Is Nothing And (Selection.Count = 1) Then
        iRow = Target.Row
        MsgBox "Row number is " & iRow
    End If
End If

End Sub