Take the code in a cell and format the e-mail using this value (VBA) (EXCEL)

Asked

Viewed 244 times

0

My problem is this:

I use a company tool that gives me a specific number for each client. When I send email to the client, I need the subject to contain this number.

With that in mind, I found a macro on the internet and adapted a little to use as my needs. Currently what I managed to do is a button that when I click, it opens the email already with the ready message (is a default email) my signature and the subject "MY COMPANY - ".

What I need, and the reason for this post, is to put the customer number right after the name of my company.

"COMPANY NAME - CUSTOMER NUMBER".

As I use a tool of my own, I would copy the client number in the system, paste it in cell A1 (for example) and when clicking the button, I would like you to open the e-mail with the right subject based on this cell.

To illustrate a little better:

Assuming the client code is 123456 and I enter that value in cell A1, by clicking the button I would like you to open an email with the subject "MY COMPANY - 123456"

Ao clicar nesse envelope, o e-mail abre conforme a próxima imagem

Gostaria que o código de cliente abrisse automático depois do "-"

  • 1

    Without the code gets too wide to answer, please create a [mcve]. But the subject of the email is usually the property Subject from Outlook mailItem.

  • Put the macro code you are using

1 answer

0


Good afternoon!

Below a very simple code to generate an email in VBA, see if you can adapt. It will need several tweaks, assuming you won’t be doing the email one by one (in which case you wouldn’t even need code...).

abs!

Sub email()

Set olapp = CreateObject("Outlook.Application")
olapp.Session.Logon

Set mensagem = olapp.CreateItem(0)
With mensagem
  .To = "destinatários"
  .CC = "com cópia"
  .BCC = "cópia oculta"
  .Subject = "Minha Empresa" & range("A1").Value
  .Body = "corpo do e-mail"
  .display
  .Send
End With

End Sub
  • I managed to fix my code using Range. Thanks paulo!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.