Automatic Save giving Error Code on opening

grapevine

Board Regular
Joined
May 23, 2007
Messages
208
(code originally discussed and tweaked on the 10th October and called Looping through all sheets except first 2)

This code below appears to be working fine and is saving the workbook with the correct extension and when you view it in My Documents it is shown with the correct picture, suffix etc, but when I open the file from My Documents, I get the following message.

"The file you are trying to open is is a different format to that supplied by the file extension. Verify that the file is not corrupted and from a trusted location" Although it then opens fine, it is causing a problem as the file is supposed to be read by another application and it cannot open the file as it cannot acknowledge the error message.

I have tried saving the file in all versions of Excel, but the same thing always occurs.

Can anyone suggest a way I can avoid this error message appearing.
Many thanks

Code:
Sub CreateNewWorkBook()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

Dim x As Integer
Dim j As Long
Dim s As String
j = Worksheets.Count
For x = 4 To j
    s = Worksheets(x).Name
    Worksheets(x).Copy
    With ActiveWorkbook
               
                 
        .SaveAs Filename:="C:\Documents and Settings\User\Desktop\Files for printing\" & s & ".csv"
        .Close
    End With
Next x
 Application.CutCopyMode = False
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try

Code:
.SaveAs Filename:="C:\Documents and Settings\User\Desktop\Files for printing\" & s & ".csv", FileFormat:=xlCSV
 
Upvote 0
Many thanks this stopped the error message from coming up. I did find that the data was displaying how I needed, so I did some further investigation based on what you had suggested and have now changed it to FileFormat:=xlExcel8.

Once again, many thanks, it really is much appreciated
 
Upvote 0

Forum statistics

Threads
1,223,287
Messages
6,171,201
Members
452,390
Latest member
kemafa77

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