SaveAs Error

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,895
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hi All
I've looked at this for a couple of hours now....and it's finally done my head, I can't see the error in the Activeworkbook.SaveAs line, where it is failing
Code:
Sub LoopFolders()
Dim oFSO
Dim Folder As Object, Files As Object, file As Object, ws As Worksheet, fldr
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("D:\Temp\Alco Tests")
For Each file In Folder.Files
If file.Type Like "*Comma Separated*" Then
Workbooks.Open Filename:=file.Path
Call Process
Application.DisplayAlerts = False
For Each ws In Worksheets
    If ws.Name Like "Sheet*" Then
        ws.Delete
    End If
Next ws
ActiveWorkbook.SaveAs Filename:=file, FileFormat:=56
End If
ActiveWorkbook.Close
Next file
Set oFSO = Nothing
Application.DisplayAlerts = True
End Sub

Any assistance to ease my pain would be appreciated.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi John
Thanks for the response.
Unfortunately, I have already tried that with no joy !!
 
Upvote 0
ActiveWorkbook.SaveAs Filename:=file.Path

without the FileFormat works for me. What is the magic number 56 anyway?
 
Upvote 0
Your line works fine if the file is to be saved as a .CSV file
However, I want the files saved as an .xls Excel 2003.
Hence the fileformat:= 56 which is the format code for Excel 2003
 
Upvote 0
I have finally made it work with this code
Code:
ActiveWorkbook.SaveAs Filename:=Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - 4) & ".xls", FileFormat:=xlNormal

I'd like to make it a bit shorter if possible, but beggars can't be choosers !!

John, thanks for your input so far, much appreciated.

I've reduced it to this
Code:
wb.SaveAs Filename:=Left(wb.FullName, Len(wb.FullName) - 4) & ".xls", FileFormat:=xlNormal
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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