Alert in opening file generated by a macro

Nelson78

Active Member
Joined
Sep 11, 2017
Messages
475
Office Version
  1. 2007
Hello everybody.

I've built a macro that generates a file with a normal extension .xls
But, when I try to open the file after saving it, the following alert appears:


Microsoft Office Excel
The file you are trying to open, 'Report.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the File. Do you want to open the file now?



Above the code.

Code:
Dim xMail As Object
Dim Location As String
Dim objWS As Object

Set objWS = CreateObject("WScript.Shell")
Location = objWS.SpecialFolders("Desktop")

Application.DisplayAlerts = False
destinazione.SaveAs Location & "\Report.xls"
destinazione.Close False
Application.DisplayAlerts = True

Set xMail = CreateObject("Outlook.Application").CreateItem(0)

With xMail
.Subject = "Communication"
    .Attachments.Add (Location & "\Report.xls")
    .Display 
End With

How can I eliminate the alert?
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,589
If you are using Excel 2007 or newer, you should use the "xlsx" extension.
Code:
destinazione.SaveAs Location & "\Report.xlsx"
.Attachments.Add (Location & "\Report.xlsx")
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,109,308
Messages
5,527,930
Members
409,793
Latest member
mavrik_stet

This Week's Hot Topics

Top