Enviar Emails com ficheiro comprimido como anexo quando estiver na Data Actual (VBA)
Pretende-se com este código que quando a Data de Envio for igual a data em que nos encontramos é enviado um email ao destinatário.
O código pesquisa todos os registos e envia para cada email onde a condição da data for a data actual.
VBA Code/Macro:
Sub SendEmail()
Dim ws As Worksheet
Dim oApp As Object, MailApp As Object, SendMail As Object
Dim strbody As String
Dim deldate As Variant
Dim email As Variant
Dim i As Integer
Set ws = Worksheets(“sheet1”)
ws.Select
‘Set numrows = number of rows of data.
NumRows = Range(“A2”, Range(“A2”).End(xlDown)).Rows.Count
‘ Select cell A2
Range(“A2”).Select
‘Get Delivery date
lin = 2
col = 4
deldate = ws.Cells(lin, col).Value
‘Get email
lin = 2
col = 7
email = ws.Cells(lin, col).Value
‘ -1 because sheet have header
For i = 1 To NumRows – 1
If deldate = Date Then
‘Create Email
Set MailApp = CreateObject(“Outlook.Application”)
Set SendMail = MailApp.CreateItem(0)
‘Conteudo corpo da mensagem
strbody = “Your require thing has been delivered … ” & vbNewLine & vbNewLine & _
“Thanks” & vbNewLine & _
“…”
On Error Resume Next
With SendMail
.To = email ‘<- Email to send
.CC = “”
.BCC = “”
.Subject = “Your require thing has been delivered …”
.Body = strbody ‘<- Body message
.Send ‘ .Display <- Before send email to client show
‘ .send <- Send Email direct
End With
Else: Exit Sub
End If
ActiveCell.Offset(lin + i, 0).Select
deldate = ws.Cells(lin + i, 4).Value
email = ws.Cells(lin + i, 7).Value
Next
End Sub
Criar ListBox Excel VBA
Creating a Listbox using Excel VBA Editor, try it 🙂
Hiperlinks VBA Excel
Criar Hiperlinks com VBA Excel:
1. Abra uma folha de Excel
2. Carregue em Alt+F11 para abrir o editor de VBA
3. Insira um novo módulo
4. Copie o código que se segue e cole na janela de codigo
5. Carregue em F5 para executar
6. Verifique que o link foi adicionado a célula A4
Create Hiperlinks with Excel VBA;
1. Open an excel workbook
2. Press Alt+F11 to open VBA Editor
3. Insert a New Module
4. Copy the above code and Paste in the code window
5. Press F5 to execute it
6. You can see a new hyperlink is added at A4
Sub CreateHyperLink()
ActiveSheet.Hyperlinks.Add Range(“A4”), “https://clicotech.blogspot.pt/”
End Sub
Teclas Atalho Excel
Sabia que:
F2 edita célula actual
F5 vai para uma célula especifica
F11 cria um grafico
ALT + PAGE DOWN move a folha para a direita no livro.
CTRL + PAGE DOWN move para a próxima folha na pasta de trabalho.
CTRL + SHIFT + PAGE DOWN selecciona a folha actual e a próxima numa pasta de trabalho.
ALT + PAGE UP move a folha para a esquerda num livro.
CTRL + PAGE UP move para o livro anterior na pasta de trabalho.
CTRL + SHIFT + PAGE UP selecciona a folha actual e a anterior na pasta de trabalho…






