.xlsb macro save as .xlsx corrupts file

AndrewI

New Member
Joined
Nov 1, 2017
Messages
40
VBA Code:
Filename_3 = Left(Filename_1, Len(Filename_1) - 10) & " UPLOAD VERSION.xlsx"


ActiveWorkbook.SaveCopyAs Filename:=Filename_3

above is a piece of code from a .xlsb file. when i save as xlsx the file is corrupted and cannot be opened.
saving as xls works but i need to make it xlsx

in another workbook i have this code and it works .

Any ideas ?
VBA Code:
Dim relativePath As String
Dim pathLength As Long
Dim pathEdit As String
Dim FinalPath As String

    relativePath = ActiveWorkbook.FullName
    pathLength = Len(relativePath)
    pathEdit = Left(relativePath, pathLength - 5)
   ' MsgBox pathEdit
    FinalPath = pathEdit & " " & SelectedView & " " & Format(Now, "yyyy-mm-dd hh-mm") & ".xlsx"
    'MsgBox FinalPath
  
    ActiveWorkbook.SaveAs Filename:=FinalPath
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
ok.. so turns out, even though the xls saves and opens via the macro (alerts turned off), when i try to open the file manually i get this error also

any help would be epic. Especially getting the .xlsx save to work.

Thanks
1587621014304.png
 
Upvote 0
Not tested your code but try adding the bit highlighted below.

Rich (BB code):
ActiveWorkbook.SaveAs Filename:=FinalPath, FileFormat:=51

Edit: Btw where is
VBA Code:
& SelectedView &
defined?
 
Last edited:
Upvote 0
Not tested your code but try adding the bit highlighted below.

Rich (BB code):
ActiveWorkbook.SaveAs Filename:=FinalPath, FileFormat:=51

Edit: Btw where is
VBA Code:
& SelectedView &
defined?
that's actually the one that worked.. it was the first piece of code that didn't and i couldn't wok out why because they seem fundamantally the same.

but i tried the fileformat approach and it worked so thank you so much.. really appreciated.

FYI.. selected view was defined in another procedure and passed to this one. it's the value of a dropdown cell.

thanks again for your help
 
Upvote 0
You're welcome. Just for info if you are changing the file type when saving then you need to state the file format .
 
Upvote 0
You're welcome. Just for info if you are changing the file type when saving then you need to state the file format .
yep.. i know that now :)... still learning bit by bit.. getting there though with help from people like you.. thanks mate
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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