Convert .xlsx workbook to .xlsb using macro

ZSauce

Board Regular
Joined
Oct 31, 2005
Messages
64
I used a macro in the past to convert 500 .xls (Excel 2 format) files to .xlsb (binary format.) I was not the author of the macro, and I would like to tweak it to now convert .xlsx files to .xlsb. What you see below contains an error that results in the converted files having an ".xlsxb" extension. Specifically, this is the incorrect code: wkbkTemp.SaveAs vFileArray(i) & "b", FileFormat:=xlExcel12

Dim vFileArray As Variant
Dim wkbkTemp As Workbook

Application.DisplayAlerts = False

vFileArray = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(vFileArray) Then
For i = LBound(vFileArray) To UBound(vFileArray)
If Right(vFileArray(i), 5) = ".xlsx" Then
Set wkbkTemp = Workbooks.Open(vFileArray(i))
wkbkTemp.SaveAs vFileArray(i) & "b", FileFormat:=xlExcel12
wkbkTemp.Close False
Else
MsgBox "This file: " & Chr(10) & vFileArray(i) & Chr(10) & "will not be processed."
End If
Next i
End If

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Well,

VBA Code:
vFileArray(i) & "b"

will give you a file name with an extension of .xlsxb. You need to do something like :

VBA Code:
wkbkTemp.SaveAs Replace(vFileArray(i)), "xlsx", "xlsb"), FileFormat:=xlExcel12

Assuming xlExcel12 gives you the xlsb format.
 
Upvote 0
Success! You put me on the right track. After I eliminated an extraneous right parenthesis after "(i)" I was in business. Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,928
Members
449,094
Latest member
teemeren

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