Private Sub Worksheet_Change(ByVal Target As Range)

arthurvvm

10-06-2015 14:49:00

Pessoal, bom dia!

Estou com uma dificuldade, na planilha anexo inseri um código para que toda vez que eu alterar algum valor na coluna W para "SIM" ele me abre o outlook para enviar um email com os dados daquela linha. Até aí tudo bem, mas não consigo deletar nenhuma coluna inteira ou linha inteira que dá um erro de tipos incompatíveis.

Gostaria de conseguir realizar essas exclusões de linha inteira ou coluna inteira.

Poderiam me ajudar a corrigir o código? Obrigado!

netocasaroli

10-06-2015 15:59:20

Cara...

Fiz duas alterações:
1. Onde estava Target.Value, alterei para Target.Text;
2. Onde informava o endereço de e-mail do destinatário estava como Plan1.Cells(linha, 22); mudei para Plan1.Cells(linha, 22).Value

Aqui pelo menos funcionou... Segue código:

Código: Selecionar todos

Private Sub Worksheet_Change(ByVal Target As Range)
   
    Dim OutApp As Object
    Dim OutMail As Object
    Dim TEXTO As String
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    linha = ActiveCell.Row 'refere-se a linha atual
'  If Not (Application.Intersect(Worksheets("BANDAS").Range("C5:c14"), Target) Is Nothing) Then
    
    If Target.Address = "$W$" & linha And Target.Text = "SIM" Or Target.Text = "sim" Then 'executa a macro a partir dessa linha se
    'o valor da coluna status for alterado.

             
        
            'Montando o texto a ser incluso no corpo do e-mail
TEXTO = "Prezado(a) " & Plan1.Cells(linha, 2) & "," + vbCrLf + vbCrLf & _
        "Esse e-mail visa lembrar sobre a necessidade de renovação do incentivo PIPD." + vbCrLf & _
        " Veja informações abaixo:" + vbCrLf + vbCrLf & _
        "    Curso: " & Plan1.Cells(linha, 6) + vbCrLf & _
        "    Categoria: " & Plan1.Cells(linha, 7) + vbCrLf & _
        "    Entidade: " & Plan1.Cells(linha, 8) + vbCrLf & _
        "    Data de Renovação: " & Format(Plan1.Cells(linha, 15), Text) + vbCrLf & _
        "    Situação: " & Plan1.Cells(linha, 13) + vbCrLf + vbCrLf & _
        "Gentileza procurar a UGP o mais breve possível para as providências." + vbCrLf + vbCrLf & _
        "Atenciosamente," + vbCrLf + vbCrLf & _
        "UGP - Unidade de Gestão de Pessoas" + vbCrLf & _
        "Equipe PIDP"
        
        

        With OutMail
            .To = Plan1.Cells(linha, 22).Value
            .CC = "teste@teste.com.br"
            .BCC = ""
            .Subject = "Assunto TESTE"
            .Body = TEXTO
            .Display   'Utilize .Send para enviar o email sem abrir o Outlook
        End With
        On Error GoTo 0

        Set OutMail = Nothing
        Set OutApp = Nothing
        
        Plan1.Range("w" & linha).Value = ""

    End If
End Sub

arthurvvm

10-06-2015 17:11:28

Funcionou, muito obrigado!!!