Excel-VBA:当从#34; ThisWorkbook"中的代码调用时,模块调用不起作用。

时间:2018-04-16 14:10:11

标签: excel excel-vba vba

我在保存时调用模块:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

With Sheets("Einstellungen")
    If .Cells(17, "C").Value = "ja" Then
        Call ModulCheck.CheckForEmptyCells '<- Idk why this is not working. Call the Sub from somewhere else and all is nice.
    End if
End With
End Sub

For Each中所谓的模数(见下文)失败(即停止运行):

Sub CheckForEmptyCells() 'check for empty cells
Dim LastRow As Integer
Dim c As Range

With Sheets("Probeninventar")
    LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row

    For Each c In .Range("E8:G" & LastRow & ",W" & LastRow).Cells
        If IsEmpty(c) Then
            If IsEmpty(Sheets("Einstellungen").Range("M5").Value) Then
                Sheets("Einstellungen").Range("M5").Value = "Datensatz unvollständig in: " & c.Row
            End if
        End if
    Next c
End With
End Sub

从工作表调用模块确实有效。从&#34;本工作手册&#34;中调用它保存后不起作用。为什么?

0 个答案:

没有答案