Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 循环在到达Email.send行后停止,无任何错误_Excel_Vba - Fatal编程技术网

Excel 循环在到达Email.send行后停止,无任何错误

Excel 循环在到达Email.send行后停止,无任何错误,excel,vba,Excel,Vba,我做了一个代码,根据手动选择发送多封电子邮件。 我的问题是,当我到达.send电子邮件时,代码不会转到下一个“For”值。它发送电子邮件,循环停止,代码从头开始,不再遵循我的For指令 这是我的密码: Sub MailTenders() ' add ref - tool -> references - > Microsoft Outlook XX.X Object Library Dim olApp As Outlook.Application Dim Email

我做了一个代码,根据手动选择发送多封电子邮件。 我的问题是,当我到达.send电子邮件时,代码不会转到下一个“For”值。它发送电子邮件,循环停止,代码从头开始,不再遵循我的For指令

这是我的密码:

Sub MailTenders()
' add ref - tool -> references - > Microsoft Outlook XX.X Object Library
    Dim olApp As Outlook.Application


    Dim Email As Outlook.MailItem


' add ref - tool -> references - > Microsoft Word XX.X Object Library
    Dim wdDoc As Word.Document '<=========


    Dim tempWB As Workbook
    Set tempWB = ActiveWorkbook
    Dim sht As Excel.Worksheet
    Set sht = tempWB.Sheets("Email")

    Dim rng As Range
    Set rng = sht.Range("A1:N22").SpecialCells(xlCellTypeVisible)
        'rng.Copy

    Dim reg As Excel.Worksheet
    Dim com As Excel.Worksheet
    Dim edata As Excel.Worksheet
    Dim lstrow As Range
    Dim lastr_nr As Long
    Dim lastc_nr As Long

    Set reg = tempWB.Sheets("Register")
    Set com = tempWB.Sheets("Companies")
    Set edata = tempWB.Sheets("Email Data")

    Dim iCounter As Integer
    Dim usermail As String
    Dim compny As String
    Dim atchm As String
    Dim emailrng As Range, cl As Range
    Dim sto As String
    Dim lc As Integer


    com.Activate
    lc = Application.CountA(com.Range("A:A"))

    For iCounter = 2 To lc 'WorksheetFunction.CountA(Columns(1))
            If Cells(iCounter, 6).Value = "x" Then

    Set olApp = New Outlook.Application
    Set Email = olApp.CreateItem(0)
    Set wdDoc = Email.GetInspector.WordEditor

    usermail = Cells(iCounter, 5).Value
    compny = Cells(iCounter, 2).Value
    atchm = Cells(iCounter, 4).Value

                reg.Activate
                Range("A1").Select
                Selection.End(xlDown).Select
                Set lstrow = ActiveCell 
                lastr_nr = ActiveCell.Row   
                Range("a" & lastr_nr + 1).Value = Range("a" & lastr_nr) + 1
                Range("b" & lastr_nr + 1).Select
                ActiveCell.FormulaR1C1 = "=NOW()"
                ActiveCell.Copy
                ActiveCell.PasteSpecial (xlPasteValues)
                Range("c" & lastr_nr + 1).Value = compny
                Range("d" & lastr_nr + 1).Value = atchm

                edata.Activate
                Range("B9").Select
                Set emailrng = Range(Selection, Selection.End(xlToRight))
                lastc_nr = ActiveCell.Column
                sto = ""
                For Each cl In emailrng
                sto = sto & ";" & cl.Value
                Next
                sto = Mid(sto, 2)

                com.Activate




    rng.Copy

        With Email
        .To = usermail
        .CC = sto
        .Subject = "Cerere oferta pentru proiectul " & edata.Range("B1").Value
        wdDoc.Range.PasteAndFormat Type:=wdFormatOriginalFormatting
'        .Display
        .Attachments.Add "c:\Users\HorbaniucVla\OneDrive - Strabag BRVZ GmbH\BL 2019\CJV Vintu - Simeria\14. Tenders\02. CP\Atasamente\" & atchm & ".zip"
        .SaveAs "c:\Users\HorbaniucVla\OneDrive - Strabag BRVZ GmbH\BL 2019\CJV Vintu - Simeria\14. Tenders\02. CP\Offers Sent\" & edata.Range("b10") & ".msg", OlSaveAsType.olMsg
        .send '!!!Here the code stops after sending the first email !!!
        End With

     reg.Activate
     Range("e" & lastr_nr + 1).Select
     Range("e" & lastr_nr + 1).Hyperlinks.Add Anchor:=Selection, Address:="c:\Users\HorbaniucVla\OneDrive - Strabag BRVZ GmbH\BL 2019\CJV Vintu - Simeria\14. Tenders\02. CP\Offers Sent\" & edata.Range("b10") & ".msg", TextToDisplay:="draft email link"
     Range("f" & lastr_nr + 1).Select
     Range("e" & lastr_nr + 1).Hyperlinks.Add Anchor:=Selection, Address:="c:\Users\HorbaniucVla\OneDrive - Strabag BRVZ GmbH\BL 2019\CJV Vintu - Simeria\14. Tenders\02. CP\Atasamente\" & atchm & ".zip", TextToDisplay:="attachement link"
    End If
    Next iCounter

End Sub
Sub-mailders()
'添加引用-工具->引用->Microsoft Outlook XX.X对象库
Dim olApp作为Outlook.Application
将电子邮件设置为Outlook.MailItem
'添加引用-工具->引用->Microsoft Word XX.X对象库

Dim wdDoc作为Word.Document'你好,我解决了它。这是一件愚蠢的事。对于lc'WorksheetFunction.CountA(Columns(1))com.Activate If Cells(iCounter,6)的iCounter=2。Value=“x”那么您好,我解决了它。这是一件愚蠢的事。对于lc'WorksheetFunction.CountA(Columns(1))的iCounter=2,com.Activate If Cells(iCounter,6)。Value=“x”然后