{"record":{"id":"5d432f75a2118ebd","repo":"qax-os/excelize","slug":"unsupported-vba-project","errorCode":null,"errorMessage":"unsupported VBA project","messagePattern":"unsupported VBA project","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":23,"sourceCode":"// Package excelize providing a set of functions that allow you to write to and\n// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and\n// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.\n// Supports complex components by high compatibility, and provided streaming\n// API for generating or reading data from a worksheet with huge amounts of\n// data. This library needs Go version 1.25.0 or later.\n\npackage excelize\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n)\n\nvar (\n\t// ErrAddVBAProject defined the error message on add the VBA project in\n\t// the workbook.\n\tErrAddVBAProject = errors.New(\"unsupported VBA project\")\n\t// ErrAttrValBool defined the error message on marshal and unmarshal\n\t// boolean type XML attribute.\n\tErrAttrValBool = errors.New(\"unexpected child of attrValBool\")\n\t// ErrCellCharsLength defined the error message for receiving a cell\n\t// characters length that exceeds the limit.\n\tErrCellCharsLength = fmt.Errorf(\"cell value must be 0-%d characters\", TotalCellChars)\n\t// ErrCellStyles defined the error message on cell styles exceeds the limit.\n\tErrCellStyles = fmt.Errorf(\"the cell styles exceeds the %d limit\", MaxCellStyles)\n\t// ErrChartTitle defined the error message on both formula and rich text for\n\t// chart title.\n\tErrChartTitle = errors.New(\"cannot set both 'Formula' and 'Paragraph' for chart title\")\n\t// ErrColumnNumber defined the error message on receive an invalid column\n\t// number.\n\tErrColumnNumber = fmt.Errorf(\"the column number must be greater than or equal to %d and less than or equal to %d\", MinColumns, MaxColumns)\n\t// ErrColumnWidth defined the error message on receive an invalid column\n\t// width.\n\tErrColumnWidth = fmt.Errorf(\"the width of the column must be less than or equal to %d characters\", MaxColumnWidth)\n\t// ErrCoordinates defined the error message on invalid coordinates tuples","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L5-L41","documentation":"ErrAddVBAProject is returned by AddVBAProject when the supplied file is not a valid vbaProject.bin OLE compound document. The library checks that the data is at least 8 bytes long and starts with the OLE identifier; if not, the project cannot be embedded in the workbook. This guards against attaching corrupted or wrong-type files.","triggerScenarios":"Calling AddVBAProject with a file shorter than 8 bytes, a file whose first 8 bytes do not match the OLE compound-document identifier (oleIdentifier), a text/JSON placeholder, or a path read that silently returned truncated data.","commonSituations":"Pointing AddVBAProject at a .xlsm/.xlsx file instead of the extracted vbaProject.bin; a download or checkout that corrupted the binary (CRLF conversion, LFS not pulled); reading a missing file into an empty/short slice and passing it on.","solutions":["Verify you are passing the actual vbaProject.bin (extracted from the xlsm), not the workbook file itself","Check the byte slice is non-empty and starts with the OLE signature D0 CF 11 E0 A1 B1 1A E1 before calling","Re-download or restore the binary with git-lfs; confirm file size matches the original","Wrap the call with errors.Is(err, excelize.ErrAddVBAProject) and surface a clear message to the user"],"exampleFix":"// before\nfile, _ := os.ReadFile(\"workbook.xlsm\")\nf.AddVBAProject(file) // ErrAddVBAProject\n// after\nfile, _ := os.ReadFile(\"vbaProject.bin\")\nif len(file) >= 8 && bytes.Equal(file[:8], []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}) {\n    f.AddVBAProject(file)\n}","handlingStrategy":"validation","validationCode":"func isOLEBinary(data []byte) bool {\n    return len(data) >= 8 && bytes.Equal(data[:8], []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1})\n}\n// call: if !isOLEBinary(vbaBin) { return errors.New(\"not a valid vbaProject.bin\") }","typeGuard":"func isValidVBAProject(b []byte) bool { return len(b) >= 8 && bytes.Equal(b[:8], oleIdentifierBytes) }","tryCatchPattern":null,"preventionTips":["Always read vbaProject.bin itself, never the containing xlsm","Check the read error and length from os.ReadFile before use","Verify the OLE magic bytes D0 CF 11 E0 A1 B1 1A E1","Store binaries with git-lfs and avoid line-ending normalization"],"tags":["vba","validation","binary-format"],"backgroundTag":"invalid-file-format","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}