Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to change display address in Macro

Hi,

I have  a macro in qvw and is it possible to change the display address. i,e when I am clicking OK the file is coming to my email but it's showing my name as display address instead of my name will it be possible to get different name.

sub ExcelFile

  strDate = CDate(Date)
  strDay = DatePart("d", strDate)
  strMonth = DatePart("m", strDate)
  strYear = DatePart("yyyy", strDate)
  If strDay < 10 Then
    strDay = "0" & strDay
  End If
  If strMonth < 10 Then
    strMonth = "0" & strMonth
  End If
  GetFormattedDate = strMonth & "-" & strDay & "-" & strYear
  Set v = ActiveDocument.Variables ("EmailAddress")
  Email=v.GetContent.String

Path = "D:\Amelia Disousa\"
FileName = "Test_" & GetFormattedDate  & ".xlsx"

set XLApp = CreateObject("Excel.Application")

XLApp.Visible = False
set XLDoc = XLApp.Workbooks.Add

ActiveDocument.GetSheetObject("CH01").CopyTableToClipboard true
XLDoc.Sheets(1).Paste()

XLDoc.Sheets(1).Columns("A:D").EntireColumn.AutoFit
XLDoc.Sheets(1).Columns("A:A").ColumnWidth = 15.57
XLDoc.Sheets(1).Columns("B:B").ColumnWidth = 12.43
XLDoc.Sheets(1).Columns("C:C").ColumnWidth = 15.29
XLDoc.Sheets(1).Columns("D:D").ColumnWidth = 15.57

XLDoc.Sheets(1).Name = "Export"
XLDoc.SaveAs Path & FileName
XLApp.Quit

Set myApp = CreateObject ("Outlook.Application")
Set myMessage = myApp.CreateItem(olMailItem)
myMessage.BodyFormat = 3 'Outlook.OlBodyFormat.olFormatRichText

myMessage.To = "amelia.disousa@xx.vv.com"
myMessage.Attachments.Add "D:\Amelia Disousa\" & FileName
myMessage.Subject = "Test File " & Date()

myMessage.Send

Set myMessage = Nothing
Set myApp = Nothing
Set myInspector = Nothing
Set myDoc = Nothing

end sub

Thanks.

32 Replies
salto
Specialist II
Specialist II

Hi,

add this line before myMessage.Send:

myMessage.From = mailusername

being mailusername the name you want to display.

Hope this helps.

Not applicable
Author

Thanks and I want to display address as Qlikview Reporting is that possible if I use

myMessage.From=Qlikview Reporting

because when Iam using this it is showing

Object doesn't support this property or method: 'myMessage.From'

Not applicable
Author

Any Help please

salto
Specialist II
Specialist II

Try using a single word for the field (for example QlikViewReporting, or enclosing the Qlikview Reporting like 'Qlikview Reporting' or double quotes.

Not applicable
Author

Thanks and it's still showing the same message as

Object doesn't support this property or method: 'myMessage.From'

Any help please as I need to get this very soon.

christian77
Partner - Specialist
Partner - Specialist

Hi Amelia.

VBasic for QlikView is not exactly the same as other VBasics.

For Qlikers get the API Guide 11.

I don't have it with me.

You can download from the site QlikView.

API Guide is a structured collection of Visual Basis sentences for QlikView.

Salutes.

flipside
Partner - Specialist II
Partner - Specialist II

I'm not sure it can be done using your method. Your code is opening the installation of Outlook on YOUR machine and therefore using your default profile. As far as I can tell it is not possible to choose which profile or email account to use when sending the message. I haven't used it but the SentOnBehalfOfName property might be a half-way solution (see this post http://answers.microsoft.com/en-us/office/forum/office_2007-outlook/trying-to-send-outlook-email-via....)

salto
Specialist II
Specialist II

Hello, there goes my function, I use this to send mails.

You can adapt this to your case and let us know if it works for you (depending on the settings on your SMTP server)

function MailReport()

    Dim objEmail

    Const cdoSendUsingPort = 2     ' Send the message using SMTP

    Const cdoAnonymous = 0     'Do not authenticate

    Const cdoBasic = 1         'basic (clear-text) authentication

    Const cdoNTLM = 2         'NTLM

    SMTPServer = "111.222.333.444"

    Const SMTPPort = 25                 ' Port number for SMTP

    Const SMTPTimeout = 60              ' Timeout for SMTP in seconds

    'Sending mail

    Set objEmail = CreateObject("CDO.Message")

    Set objConf = objEmail.Configuration

    Set objFlds = objConf.Fields

    With objFlds

        '---------------------------------------------------------------------

           ' SMTP server details

           .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort 'ok

           .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer      'ok

           .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic  'ok

          

           .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxyyy"

           .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"         

             .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

           .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

           .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout

           .Update

        '---------------------------------------------------------------------

    End With

    objEmail.To = "recipient@mydomain.com"        'Email Recipient

    objEmail.From = "QlikView Reporting"                        'Email Sender

    objEmail.Subject = "Dashboard"                        ' Subject

    objEmail.TextBody = "Body"        'Text Body         

   

    objEmail.Send

    Set objFlds = Nothing

    Set objConf = Nothing

    Set objEmail = Nothing

end function

marcus_sommer

I believe this isn't possible - I haven't seen any example with this feature. I think it is a security feature like the delaying and the additionally confirm from sending mails if you accessed outlook from outside - you should not change the sender, it could be spam or a virus ... it is MS thinking ...

If you used cdo.message instead from outlook you could set any sender you want.

- Marcus