Fazerbem
28-03-2016 22:45:50
Tenho a macro abaixo, e preciso conforme a conta selecionada por uma celula, usar a assinatura referente a conta selecionada.
Podem me ajudar a adaptar o comando na macro abaixo ?
Sub X_Lojas()
' Lojas Gerais
'Setting up the Excel variables.
Dim OlApp As Outlook.Application
Dim OlMensagem As Outlook.MailItem
Dim iCounter As Integer
Dim Dest As Variant
Dim SDest As String
Dim Estado As String
Dim BuscaEstado As Range
Dim AbrevEstado As String
Dim Leitura As String
Dim contaEmail As String
Dim idEmail As Integer
Dim strbody As String
Dim Loja As String
Loja = Range("A1")
Dim Assunto As String
Assunto = Range("L1")
If Sheets(Loja).Range("K4").Value = "" Then
MsgBox ("Qual Empresa associar esta Mensagem 1-Gauer do Brasil ou 2-Leader Nutrition ?")
Range("K4").Select
GoTo Fim
Else
End If
If Sheets(Loja).Range("Q4").Value = "" Then
MsgBox ("A conta de E-mail não foi associada !")
GoTo Fim
Else
End If
If Sheets(Loja).Range("F7").Value = 1 Then
strbody = "<H2>" & _
Sheets(Loja).Range("AD2").Value & _
"</H2>" & _
"<H3 style='color: #870c0c'>" & _
Sheets(Loja).Range("AD6").Value & _
"</H3>" & _
"<H3>" & _
Sheets(Loja).Range("AD10").Value & _
"<br><br>" & _
Sheets(Loja).Range("AD14").Value & _
"<br><br>" & _
Sheets(Loja).Range("AD18").Value & _
"<br><br>"
GoTo Continuar
Else
If Sheets(Loja).Range("K4").Value = 1 Then
strbody = "<H2>" & _
Sheets(Loja).Range("V2").Value & _
"</H2>" & _
"<H3 style='color: #870c0c'>" & _
Sheets(Loja).Range("V6").Value & _
"</H3>" & _
"<H3>" & _
Sheets(Loja).Range("V10").Value & _
"<br><br>" & _
Sheets(Loja).Range("V14").Value & _
"<br><br>" & _
Sheets(Loja).Range("V18").Value & _
"<br><br>" & _
Sheets(Loja).Range("V22").Value & _
"<br><br>"
Else
strbody = "<H2>" & _
Sheets(Loja).Range("Z2").Value & _
"</H2>" & _
"<H3 style='color: #870c0c'>" & _
Sheets(Loja).Range("Z6").Value & _
"</H3>" & _
"<H3>" & _
Sheets(Loja).Range("Z10").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z14").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z18").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z22").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z23").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z24").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z25").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z26").Value & _
"<br><br>"
End If
End If
GoTo Continuar
Continuar:
Leitura = Sheets(Loja).Range("I7")
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Pular2
Else
End If
Estado = Application.Caller
Application.ScreenUpdating = False
Sheets(Estado).Visible = True
GoTo Pular2
Pular2:
Application.DisplayAlerts = False 'desabilite o alerta
'------------------------------------------------------------
'DVitaminas/SNC/......
If Sheets(Loja).Range("E15").Value = 1 Then
GoTo Pular
Else
End If
'-----------------------------------------------------------
Range("L2").Select
Set BuscaEstado = ThisWorkbook.ActiveSheet.Range("A3:A30").Find(Estado, LookIn:=xlValues, LookAt:=xlWhole)
If BuscaEstado Is Nothing Then
MsgBox "Estado não localizado"
GoTo Fim
Else
AbrevEstado = ThisWorkbook.Worksheets(Loja).Cells(BuscaEstado.Row, 1).Value
End If
GoTo Pular
Pular:
' Preste atencao aqui
contaEmail = ThisWorkbook.Sheets(Loja).Range("I8").Value
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Pular3
Else
End If
'Quero que aqui, ao inves de ter RJ tenha a variavel Estado que vai estar associado ao click na regiao do mapa.
ThisWorkbook.Worksheets(AbrevEstado).Select
GoTo Pular3
Pular3:
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
iCounter = 2
GoTo Proximo1
Else
End If
iCounter = 1
GoTo Proximo1
Proximo1:
'Create the Outlook application and the empty email.
Set OlApp = CreateObject("Outlook.Application")
Set OlMensagem = OlApp.CreateItem(0)
'------------------------------------------------------------------------------
'Este laço verifica se o nome da conta w no registro do windows é igual ao valor da célula
For w = 1 To OlApp.Session.Accounts.Count
If OlApp.Session.Accounts.Item(w).DisplayName = contaEmail Then 'Se for verdadeiro, solicita confirmação
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Proximo
Else
End If
If MsgBox("O E-mail será enviado usando a conta " & contaEmail & ". Confirma ?" & " ( Estado - " & Estado & " )", vbQuestion + vbYesNo, "Envio de e-mail") = vbYes Then
GoTo Proximo
Proximo:
idEmail = w 'Define o id da conta para o comando enviar
Exit For 'Sai do laço
Else
Sheets(Estado).Visible = False
Sheets(Loja).Select
GoTo Fim 'Senão sai da rotina
End If
End If
Next
'-------------------------------------------------------------------------------
'Using the email, add multiple recipients, using a list of addresses in column C.
With OlMensagem
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
For iCounter = 2 To WorksheetFunction.CountA(Columns(3))
' Sheets("Email").Select
SDest = SDest & ";" & Cells(iCounter, 3).Value
Next iCounter
GoTo Proximo2
Else
End If
For iCounter = 1 To WorksheetFunction.CountA(Columns(3))
' Sheets("Email").Select
SDest = SDest & ";" & Cells(iCounter, 3).Value
Next iCounter
GoTo Proximo2
Proximo2:
'-------------------------------------------------------------
'---------------------------------------------------------------
'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send.
.Display
.BCC = SDest
.Subject = Assunto '"Tabela de Pedidos"
.HTMLBody = strbody & .HTMLBody
If Sheets(Loja).Range("F1").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\" & Sheets(Loja).Range("F1").Value & Sheets(Loja).Range("I1").Value
Else
End If
If Sheets(Loja).Range("F2").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\" & Sheets(Loja).Range("F2").Value & Sheets(Loja).Range("I2").Value
Else
End If
If Sheets(Loja).Range("F3").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\Banner\" & Sheets(Loja).Range("F3").Value & Sheets(Loja).Range("I3").Value
Else
End If
If Sheets(Loja).Range("F4").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\Banner\" & Sheets(Loja).Range("F4").Value & Sheets(Loja).Range("I4").Value
Else
End If
If Sheets(Loja).Range("I6").Value = "SEND" Then
.ReadReceiptRequested = Leitura ' confirmação de leitura
.SendUsingAccount = OlApp.Session.Accounts.Item(idEmail)
.Send
Else
.ReadReceiptRequested = Leitura ' confirmação de leitura
.SendUsingAccount = OlApp.Session.Accounts.Item(idEmail)
.Display
End If
Sheets(Loja).Select
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Pular4
Else
End If
Sheets(Estado).Visible = False
GoTo Pular4
Pular4:
GoTo Fim
End With
Exit Sub
Fim:
'Clean up the Outlook application.
Set BuscaEstado = Nothing
Set OlMensagem = Nothing
Set OlApp = Nothing
End Sub
Podem me ajudar a adaptar o comando na macro abaixo ?
Sub X_Lojas()
' Lojas Gerais
'Setting up the Excel variables.
Dim OlApp As Outlook.Application
Dim OlMensagem As Outlook.MailItem
Dim iCounter As Integer
Dim Dest As Variant
Dim SDest As String
Dim Estado As String
Dim BuscaEstado As Range
Dim AbrevEstado As String
Dim Leitura As String
Dim contaEmail As String
Dim idEmail As Integer
Dim strbody As String
Dim Loja As String
Loja = Range("A1")
Dim Assunto As String
Assunto = Range("L1")
If Sheets(Loja).Range("K4").Value = "" Then
MsgBox ("Qual Empresa associar esta Mensagem 1-Gauer do Brasil ou 2-Leader Nutrition ?")
Range("K4").Select
GoTo Fim
Else
End If
If Sheets(Loja).Range("Q4").Value = "" Then
MsgBox ("A conta de E-mail não foi associada !")
GoTo Fim
Else
End If
If Sheets(Loja).Range("F7").Value = 1 Then
strbody = "<H2>" & _
Sheets(Loja).Range("AD2").Value & _
"</H2>" & _
"<H3 style='color: #870c0c'>" & _
Sheets(Loja).Range("AD6").Value & _
"</H3>" & _
"<H3>" & _
Sheets(Loja).Range("AD10").Value & _
"<br><br>" & _
Sheets(Loja).Range("AD14").Value & _
"<br><br>" & _
Sheets(Loja).Range("AD18").Value & _
"<br><br>"
GoTo Continuar
Else
If Sheets(Loja).Range("K4").Value = 1 Then
strbody = "<H2>" & _
Sheets(Loja).Range("V2").Value & _
"</H2>" & _
"<H3 style='color: #870c0c'>" & _
Sheets(Loja).Range("V6").Value & _
"</H3>" & _
"<H3>" & _
Sheets(Loja).Range("V10").Value & _
"<br><br>" & _
Sheets(Loja).Range("V14").Value & _
"<br><br>" & _
Sheets(Loja).Range("V18").Value & _
"<br><br>" & _
Sheets(Loja).Range("V22").Value & _
"<br><br>"
Else
strbody = "<H2>" & _
Sheets(Loja).Range("Z2").Value & _
"</H2>" & _
"<H3 style='color: #870c0c'>" & _
Sheets(Loja).Range("Z6").Value & _
"</H3>" & _
"<H3>" & _
Sheets(Loja).Range("Z10").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z14").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z18").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z22").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z23").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z24").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z25").Value & _
"<br><br>" & _
Sheets(Loja).Range("Z26").Value & _
"<br><br>"
End If
End If
GoTo Continuar
Continuar:
Leitura = Sheets(Loja).Range("I7")
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Pular2
Else
End If
Estado = Application.Caller
Application.ScreenUpdating = False
Sheets(Estado).Visible = True
GoTo Pular2
Pular2:
Application.DisplayAlerts = False 'desabilite o alerta
'------------------------------------------------------------
'DVitaminas/SNC/......
If Sheets(Loja).Range("E15").Value = 1 Then
GoTo Pular
Else
End If
'-----------------------------------------------------------
Range("L2").Select
Set BuscaEstado = ThisWorkbook.ActiveSheet.Range("A3:A30").Find(Estado, LookIn:=xlValues, LookAt:=xlWhole)
If BuscaEstado Is Nothing Then
MsgBox "Estado não localizado"
GoTo Fim
Else
AbrevEstado = ThisWorkbook.Worksheets(Loja).Cells(BuscaEstado.Row, 1).Value
End If
GoTo Pular
Pular:
' Preste atencao aqui
contaEmail = ThisWorkbook.Sheets(Loja).Range("I8").Value
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Pular3
Else
End If
'Quero que aqui, ao inves de ter RJ tenha a variavel Estado que vai estar associado ao click na regiao do mapa.
ThisWorkbook.Worksheets(AbrevEstado).Select
GoTo Pular3
Pular3:
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
iCounter = 2
GoTo Proximo1
Else
End If
iCounter = 1
GoTo Proximo1
Proximo1:
'Create the Outlook application and the empty email.
Set OlApp = CreateObject("Outlook.Application")
Set OlMensagem = OlApp.CreateItem(0)
'------------------------------------------------------------------------------
'Este laço verifica se o nome da conta w no registro do windows é igual ao valor da célula
For w = 1 To OlApp.Session.Accounts.Count
If OlApp.Session.Accounts.Item(w).DisplayName = contaEmail Then 'Se for verdadeiro, solicita confirmação
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Proximo
Else
End If
If MsgBox("O E-mail será enviado usando a conta " & contaEmail & ". Confirma ?" & " ( Estado - " & Estado & " )", vbQuestion + vbYesNo, "Envio de e-mail") = vbYes Then
GoTo Proximo
Proximo:
idEmail = w 'Define o id da conta para o comando enviar
Exit For 'Sai do laço
Else
Sheets(Estado).Visible = False
Sheets(Loja).Select
GoTo Fim 'Senão sai da rotina
End If
End If
Next
'-------------------------------------------------------------------------------
'Using the email, add multiple recipients, using a list of addresses in column C.
With OlMensagem
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
For iCounter = 2 To WorksheetFunction.CountA(Columns(3))
' Sheets("Email").Select
SDest = SDest & ";" & Cells(iCounter, 3).Value
Next iCounter
GoTo Proximo2
Else
End If
For iCounter = 1 To WorksheetFunction.CountA(Columns(3))
' Sheets("Email").Select
SDest = SDest & ";" & Cells(iCounter, 3).Value
Next iCounter
GoTo Proximo2
Proximo2:
'-------------------------------------------------------------
'---------------------------------------------------------------
'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send.
.Display
.BCC = SDest
.Subject = Assunto '"Tabela de Pedidos"
.HTMLBody = strbody & .HTMLBody
If Sheets(Loja).Range("F1").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\" & Sheets(Loja).Range("F1").Value & Sheets(Loja).Range("I1").Value
Else
End If
If Sheets(Loja).Range("F2").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\" & Sheets(Loja).Range("F2").Value & Sheets(Loja).Range("I2").Value
Else
End If
If Sheets(Loja).Range("F3").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\Banner\" & Sheets(Loja).Range("F3").Value & Sheets(Loja).Range("I3").Value
Else
End If
If Sheets(Loja).Range("F4").Value > 0 Then
.Attachments.Add "C:\Users\Andre\Desktop\Pedidos Gauer\Banner\" & Sheets(Loja).Range("F4").Value & Sheets(Loja).Range("I4").Value
Else
End If
If Sheets(Loja).Range("I6").Value = "SEND" Then
.ReadReceiptRequested = Leitura ' confirmação de leitura
.SendUsingAccount = OlApp.Session.Accounts.Item(idEmail)
.Send
Else
.ReadReceiptRequested = Leitura ' confirmação de leitura
.SendUsingAccount = OlApp.Session.Accounts.Item(idEmail)
.Display
End If
Sheets(Loja).Select
If Sheets(Loja).Range("A1").Value = "DVitaminas" Then
GoTo Pular4
Else
End If
Sheets(Estado).Visible = False
GoTo Pular4
Pular4:
GoTo Fim
End With
Exit Sub
Fim:
'Clean up the Outlook application.
Set BuscaEstado = Nothing
Set OlMensagem = Nothing
Set OlApp = Nothing
End Sub