需要使用 VBA 将 xls 工作簿另存为 xlsb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31654526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:49:19  来源:igfitidea点击:

Need to save xls workbook As xlsb with VBA

excelexcel-vbavba

提问by Steve Smith

I use a macro to create a daily report. The macro saves the xls report as xls historically. Due to large file size I want to save the report as xlsb. Two problems. The macro script i am using will run but I cannot open the xlsb file later. Message received is

我使用宏来创建每日报告。宏历史上将 xls 报告保存为 xls。由于文件较大,我想将报告另存为 xlsb。两个问题。我正在使用的宏脚本将运行,但稍后我无法打开 xlsb 文件。收到的消息是

"Excel cannot open the file'RDN Activity Report.xlsb' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

“Excel 无法打开文件‘RDN 活动报告.xlsb’,因为文件格式或文件扩展名无效。请验证文件是否已损坏,并且文件扩展名是否与文件格式匹配。

txtFileName = Format(Date - 1, "yyyymmdd")
ActiveWorkbook.SaveAs Filename:= _
    "\Clt-stor01a\CA_Services\RDN Reports\ForUploadPrev\RDN Activity Report." & txtFileName & ".xlsb", _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False
    txtFileName = Format(Date - 1, "yyyymmdd")

Note: I also need a script that can open a file when file name has date in file name and date of file is yesterday's date such as "RDN Activity Report.20150726"

注意:我还需要一个脚本,当文件名在文件名中有日期并且文件的日期是昨天的日期时,例如“ RDN Activity Report.20150726”,我还需要一个可以打开文件的脚本

回答by MatthewD

Use SaveAsparameter FileFormat:

使用SaveAs参数FileFormat

  • 50= xlExcel12(Excel Binary Workbook in 2007-2013 with or without macro's, xlsb)

  • 51= xlOpenXMLWorkbook(without macro's in 2007-2013, xlsx)

  • 52= xlOpenXMLWorkbookMacroEnabled(with or without macro's in 2007-2013, xlsm)

  • 56= xlExcel8(97-2003 format in Excel 2007-2013, xls)

    ActiveWorkbook.SaveAs "C:\temp\text.xlsb", fileformat:=50
    
  • 50= xlExcel12(2007-2013 年的 Excel 二进制工作簿,带或不带宏,xlsb)

  • 51= xlOpenXMLWorkbook(2007-2013 年没有宏,xlsx)

  • 52= xlOpenXMLWorkbookMacroEnabled(2007-2013 年有或没有宏,xlsm)

  • 56= xlExcel8(Excel 2007-2013 中的 97-2003 格式,xls)

    ActiveWorkbook.SaveAs "C:\temp\text.xlsb", fileformat:=50