Проверка наличия объекта OLE на листе - PullRequest
0 голосов
/ 22 января 2019

Я работаю над формой пользователя, которая требует от пользователя прикрепить файл в Excel.

Я пытаюсь создать элемент управления в пользовательской форме. Я поместил командную кнопку «Сохранить и закрыть» в форме, которая проверяет, все ли поля были заполнены пользователем и все вложения были прикреплены.

У меня проблема с проверкой вложений на листе. Как заставить VBA проверить, существуют ли какие-либо объекты OLE в моей рабочей таблице, которые были прикреплены пользователем?

'Ниже приведен мой код для проверки и ввода в файл

Private Sub SAC_Click()
    If CLN.Text = "" Then
        MsgBox ("Company Legal Name is a mandatory field!")
    Else
        Range("A2").Value = CLN.Text
    End If

    If BRL.Text = "" Then
        MsgBox ("Business Registration/ License is a mandatory field!")
    Else
        Range("B2").Value = BRL.Text
    End If

    If COA.Text = "" Then
        MsgBox ("Company Address is a mandatory field!")
    Else
        Range("C2").Value = COA.Text
    End If

    Range("D2").Value = PON.Text
    Range("E2").Value = TNR.Text

    If BLA.Text = "" Then
        MsgBox ("Billing Address is a mandatory field!")
    Else
        Range("F2").Value = BLA.Text
    End If

'VAT Registration data

    If VRN.Text = "" Then
        MsgBox ("VAT Registration Number is a mandatory field!")
    Else
        Range("G2").Value = VRN.Text
    End If

If VRD.Text = "" Then
        MsgBox ("VAT Registration Date is a mandatory field!")
    Else
        Range("H2").Value = VRD.Text
    End If

If COR.Text = "" Then
        MsgBox ("Country of Registration is a mandatory field!")
    Else
        Range("I2").Value = COR.Text
    End If

'Finance information data
'Payment Terms
If PmtTerms.Text = "" Then
        MsgBox ("Payment Terms is a mandatory field!")
    Else
        Range("J2").Value = PmtTerms.Text
    End If

If PmtMtd.Text = "" Then
        MsgBox ("Method of Payment is a mandatory field!")
    Else
        Range("K2").Value = PmtMtd.Text
    End If

'Finance other contacts

If NAS.Text = "" Then
        MsgBox ("Name of Authorized Signatory is a mandatory field!")
    Else
        Range("L2").Value = NAS.Text
    End If

If EMA.Text = "" Then
        MsgBox ("E-mail address is a mandatory field!")
    Else
        Range("M2").Value = EMA.Text
    End If

If MNR.Text = "" Then
        MsgBox ("Mobile number is a mandatory field!")
    Else
        Range("N2").Value = MNR.Text
    End If

If FCF.Text = "" Then
        MsgBox ("Finace contact is a mandatory field!")
    Else
        Range("O2").Value = FCF.Text
    End If

If EMA2.Text = "" Then
        MsgBox ("Finace E-mail address is a mandatory field!")
    Else
        Range("P2").Value = EMA2.Text
    End If

If MNR2.Text = "" Then
        MsgBox ("Finace mobile number is a mandatory field!")
    Else
        Range("Q2").Value = MNR2.Text
    End If

'Business contact information

    Range("R2").Value = CFN.Text
    Range("S2").Value = EMA3.Text
    Range("T2").Value = MNR3.Text

'Testing saving control


End Sub

1 Ответ

0 голосов
/ 22 января 2019

ThisWorkbook.Sheets(1).oleobjects.Count будет нулевым, если на листе нет объектов OLEObject.Если у вас есть несколько существующих объектов, то, если вы знаете, сколько объектов вы начали, то вы можете проверить, увеличилось ли оно на единицу, чтобы определить, был ли он добавлен

...