Excel / Макро / Email.Как удалить функцию цикла из этого кода VBA и запустить каждую строку отдельно? - PullRequest
0 голосов
/ 25 февраля 2019

я впервые задаю здесь вопрос, был бы очень признателен, если бы я мог удалить цикл и запустить макрос построчно вручную?

Sub Email()
   Dim olApp As Object
   Dim olMail As Object
   Dim olRecip As Object
   Dim iRow As Long
   Dim Recip As String
   Dim Subject As String


   iRow = 2

   Set olApp = CreateObject("Outlook.Application")

   Do Until IsEmpty(Cells(iRow, 1))

      Recip = Cells(iRow, 1).Value
      Subject = Cells(iRow, 3).Value


      Set olMail = olApp.CreateItem(0)

      With olMail
         Set olRecip = .Recipients.Add(Recip)
        .Display
        .CC = ""
        .Subject = ""
        .HTMLbody = "<html><body><p>Dear " & Cells(iRow, 2).Value & "," & "<br>" & "<br>" & "summary " & Cells(iRow, 3).Value & " summary" & Cells(iRow, 4).Value & "summary" & "<br>" & "<br>" & "summary" & "<br>" & "<br>" & "conclusion" & .HTMLbody
         olRecip.Resolve
        .Display

      End With

      iRow = iRow + 1

   Loop

   Set olApp = Nothing

Exit Sub

End Sub

Ответы [ 2 ]

0 голосов
/ 27 февраля 2019

Вы пытаетесь отладить?Я думаю, что вы хотите сделать, это нажать F8, чтобы войти в код.

0 голосов
/ 25 февраля 2019

прокомментируйте свой код

Sub Email() Dim olApp As Object Dim olMail As Object Dim olRecip As Object Dim iRow As Long Dim Recip As String Dim Subject As String

    iRow = 2

    Set olApp = CreateObject("Outlook.Application")

    'If column A has more the 1 email, will send/display email 1 at a time
    'Do Until IsEmpty(Cells(iRow, 1))      

      Recip = Cells(iRow, 1).Value
      Subject = Cells(iRow, 3).Value


      Set olMail = olApp.CreateItem(0)

      With olMail
         Set olRecip = .Recipients.Add(Recip)
        .Display
        .CC = ""
        .Subject = ""
        .HTMLbody = "<html><body><p>Dear " & Cells(iRow, 2).Value & "," & "<br>" & "<br>" & "summary " & Cells(iRow, 3).Value & " summary" & Cells(iRow, 4).Value & "summary" & "<br>" & "<br>" & "summary" & "<br>" & "<br>" & "conclusion" & .HTMLbody
         olRecip.Resolve
        .Display

      End With

      iRow = iRow + 1

    'Msgbox to show email was sent or failed
    'Loop

    Set olApp = Nothing

    Exit Sub

    End Sub '
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...