Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddVBAProject limitations #1148

Closed
JDavidVR opened this issue Feb 16, 2022 · 1 comment
Closed

AddVBAProject limitations #1148

JDavidVR opened this issue Feb 16, 2022 · 1 comment

Comments

@JDavidVR
Copy link
Contributor

Description
I'm trying to use AddVBAProject function but it has its limitations when vba code is in ThisWorkbook

I've created a file using MS Excel 2010

image

So I've extracted the vbaProject.bin from the above file and use it to add to a file generated with excelize, and it looks different
image

Steps to reproduce the issue:

  1. Create a file manually using excel, and add code to ThisWorkbook for example MsgBox "Hi..!!"
  2. Extract the vbaProject.bin
  3. Execute this code
f := excelize.NewFile()

if err := f.SetSheetPrOptions("Sheet1", excelize.CodeName("Sheet1")); err != nil {
    fmt.Println(err)
}

if err := f.AddVBAProject("vbaProject.bin"); err != nil {
    fmt.Println(err)
}

if err := f.SaveAs("macros.xlsm"); err != nil {
    fmt.Println(err)
}
  1. Open with Excel, it won't execute the vba code

Describe the results you received:
image

Describe the results you expected:
image

Output of go version:
go version go1.17.6 darwin/amd64

Excelize version or commit ID:
branch: master
commit: ad09698515b4f70496c950cca02ce612af8170e0

Environment details (OS, Microsoft Excel™ version, physical, etc.):
macos Big Sur 11.4

Investigation
I've compared files between:

  • File generated manually
  • File generated with go

Results: excelize generated all the necessary information BUT it has some missing changes for xl/workbook.xml

By MS Excel

<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
          xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          
          <workbookPr codeName="ThisWorkbook" defaultThemeVersion="124226"/>

By Excelize

<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
          xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15">
          
          <workbookPr defaultThemeVersion="164011" filterPrivacy="true"></workbookPr>

So:
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15" this line it's causing the issue
and
<workbookPr tag need and additional param codeName="ThisWorkbook"

@JDavidVR
Copy link
Contributor Author

@xuri I've created a PR, the quick solution would be modify the template for workbook 9144ff1

@xuri xuri closed this as completed in f87c39c Feb 16, 2022
xuri added a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
…to the workbook

Added two exported functions `SetWorkbookPrOptions` and `GetWorkbookPrOptions` to support setting and getting the code name property of the workbook
Re-order fields of the workbook properties group to improve the compatibility
Go Modules dependencies upgrade
Put workbook related operating in new `workbook.go` source code
Library introduction docs block updated
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
…to the workbook

Added two exported functions `SetWorkbookPrOptions` and `GetWorkbookPrOptions` to support setting and getting the code name property of the workbook
Re-order fields of the workbook properties group to improve the compatibility
Go Modules dependencies upgrade
Put workbook related operating in new `workbook.go` source code
Library introduction docs block updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant