2016-09-06 25 views
1

我有一個電子表格,它已啓用宏。 在'ThisWorkbook'區域中,我有一個例程來檢查用戶可以點擊的位置。 下面是代碼的摘錄:啓用編輯後,範圍(「My_Name」)失敗

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」)方法失敗。 消息框允許您「結束」或「調試」。 如果您點擊'結束',那麼消息框將清除,並且程序從這一點開始工作正常。

任何想法發生了什麼?我該如何阻止這種情況發生,因此如果我的用戶面臨「爆炸」的情況呢?

豐富

回答

0

只是爲了確保,你所定義的命名範圍「QuoteNumber」爲工作簿範圍,對不對?此外,「QuoteNumber」範圍是在此工作簿。

予定義的 「QuoteNumber」 爲工作簿範圍,它的範圍是 「Repot」 手冊,我使用的範圍(A1:C10)。 當我通過電子郵件發送本工作手冊(附帶下面的代碼)和我的同事(在他的PC上)單擊「報告」單元格(單元格B3)中Range(A1:C10)中的一個單元格時, 「行號是3」的測試MsgBox

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 
+0

是的,我的QuoteNumber位於此工作表上,並且範圍爲Workbook。 當您將文件發送給您的朋友時,他是否收到要啓用編輯的消息?這是當你點擊啓用編輯按鈕發生錯誤。 – rtemen