Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por wpceid
#25062
Bom dia amigos!

Estou com uma macro que envia e-mails através de um intervalo de células. O destinatário, o assunto e o corpo do e-mail estão em intervalor.

Segue o código:
Código: Selecionar todos
Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
'Working in Excel 2002-2016
    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range
    Dim destinatario As Range
    Dim assunto As Range


    On Error GoTo StopMacro

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    'Fill in the Worksheet/range you want to mail
    'Note: if you use one cell it will send the whole worksheet
    Set Sendrng = Worksheets("Plan1").Range("B1:Q19")

    'Remember the activesheet
    Set AWorksheet = ActiveSheet
    Set destinatario = Worksheets("E-mail").Range("L11")
    Set assunto = Worksheets("E-mail").Range("L13")

    With Sendrng

        ' Select the worksheet with the range you want to send
        .Parent.Select

        'Remember the ActiveCell on that worksheet
        Set rng = ActiveCell

        'Select the range you want to mail
        .Select

        ' Create the mail and send it
        ActiveWorkbook.EnvelopeVisible = True
        With .Parent.MailEnvelope
        
      
           With .Item
                .To = destinatario.Value
                .Subject = assunto.Value
                .display

            End With

        End With

        'select the original ActiveCell
        rng.Select
    End With

    'Activate the sheet that was active before you run the macro
    AWorksheet.Select

StopMacro:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    
  
    ActiveWorkbook.EnvelopeVisible = False

End Sub
Entretanto, eu gostaria que antes de enviar o e-mail, a macro deixasse ele aberto para que eu enviasse ele manualmente. O .display não está dando certo :/

Obrigada desde já!!
Avatar do usuário
Por alexandrevba
Avatar
#25109
Bom dia!!

Já tentou algo assim.
Código: Selecionar todos
Sub Tente()
    Dim ans As VbMsgBoxResult
    
    ans = MsgBox("Deseja enviar o Email?", vbQuestion + vbYesNoCancel, "Enviar Email?")
    
    If ans = vbYes Then
           Call Send_Range_Or_Whole_Worksheet_with_MailEnvelope
           'Ou use essa lógica para disparar a opção-> .send
    Else
        Exit Sub
    End If
    
End Sub
Att
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord