.xls file saved by VBA gives file format does not match file extension error message when opening

Andyatwork

Board Regular
Joined
Mar 29, 2010
Messages
94
Hi all,

I'm using the below code to prompt users to save the finished output from a macrobook and while the file can be opened safely, it throws up an error message;
"the file you are trying to open, "...filename here...<FILENAME>" is in a different format than specified by the file extension. Verify that the file is not corrupted".. etc

Is there a change I can make so that the format will match the file extension and the error message will not be generated when the file recipient tries to open the file? They are a panicky bunch and will scream "virus! kill it with fire!".

I'm using excel07 on Win XP to produce the file which must be saved as .xls.

Code:
Sub Save_file_as()
    Dim iMsg As Byte
    Dim iFileName As String     'initial file name
    Set wb = ActiveWorkbook
    
    iFileName = ThisWorkbook.Path & "\Report " & format(Date, "dd.mm.yyyy") & ".xls"
        iMsg = MsgBox("Report preparation complete." & vbCrLf & _
        "Do you want to save the file?", vbYesNo + vbQuestion, "Save completed report?")
    
    If iMsg = 6 Then
        repname = Application.GetSaveAsFilename(InitialFileName:=iFileName, _
        filefilter:="Excel files, *.xls")
        With opwb
            If repname <> "False" Then
                .SaveAs repname
            Else
                Exit Sub
            End If
        End With
      Else
        Exit Sub
    End If
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try adding the FileFormat argument to SaveAs.

Code:
.Saves repname, FileFormat:=xlExcel8
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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