saving .xlsx as .xlsx or .xlsm the file format or extension is not valid

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
439
Office Version
  1. 2016
hello,

I have the below. It basically saves the file to get rid of digital signatures and the file being marked as final. I need to be able to access the file with vba so im trying to save it to get rid of the permissions restrictions. The cod runs however when I try and open the saved file it give the file format or extension is not valid error message. I have tried to save as .xls .xlsx .xlsm and non seem to work. Any thoughts?

VBA Code:
Sub ChangeFileFormat()
    Dim Folder As String, FileName As String, folder2 As String
    Dim wb As Workbook
    Application.DisplayAlerts = False
    Folder = "C:\Users\jordan.burch.ctr\Desktop\CERT STATEMENTS 3\"
     folder2 = "C:\Users\jordan.burch.ctr\Desktop\CERT STATEMENTS\"
   
    FileName = Dir(Folder & "*.xls*", vbNormal)
   
    On Error GoTo exitsub
    With Application
        .EnableEvents = False: .ScreenUpdating = False
    End With
    Do While FileName <> ""
       
        Set wb = Workbooks.Open(Folder & FileName)
        FileName = Replace(FileName, ".xls*", ".xlsm")
        If FileName <> ThisWorkbook.Name Then
            wb.SaveAs FileName:=folder2 & FileName, FileFormat:= _
            xlExcel8, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
        End If
       
        wb.Close False
       
        FileName = Dir
        Set wb = Nothing
    Loop
exitsub:
    With Application
        .EnableEvents = True: .ScreenUpdating = True
    End With
    If Err > 0 Then MsgBox (Error(Err)), 48, "error"
    Application.DisplayAlerts = True
End Sub


Jordan
 
Last edited by a moderator:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Do you want to save as an xlsm file?
 
Upvote 0
In that case use
VBA Code:
 wb.SaveAs FileName:=folder2 & FileName, FileFormat:= _
            52, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
Also in future please post your code in code tags How to Post Your VBA Code
 
Upvote 0
In that case use
VBA Code:
 wb.SaveAs FileName:=folder2 & FileName, FileFormat:= _
            52, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
Also in future please post your code in code tags How to Post Your VBA Code
Thanks Fluff will do. I tried your code and now it says the extension cannot be used with the selected file type.

Jordan
 
Upvote 0
Also use this
VBA Code:
FileName = Left(FileName, InStrRev(FileName, ".")) & "xlsm"
you cannot use wildcards with replace
 
Upvote 0
worked like a charm you are the best! what was wrong with the original code?

thanks

Jordan
 
Last edited by a moderator:
Upvote 0
Partly what I said in post#6 & partly you were saving it as an xls fileformat with xlExcel8,
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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