Alert in opening file generated by a macro

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
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?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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:
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top