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

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
394
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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
Do you want to save as an xlsm file?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
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
 

jordanburch

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

ADVERTISEMENT

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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
Also use this
VBA Code:
FileName = Left(FileName, InStrRev(FileName, ".")) & "xlsm"
you cannot use wildcards with replace
 

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
394
Office Version
  1. 2016
worked like a charm you are the best! what was wrong with the original code?

thanks

Jordan
 
Last edited by a moderator:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
Partly what I said in post#6 & partly you were saving it as an xls fileformat with xlExcel8,
 

Forum statistics

Threads
1,147,735
Messages
5,742,866
Members
423,760
Latest member
photogfrog

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
Top