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

imported xlsm shoud write temp xlsm for wb$open() #200

Closed
JanMarvin opened this issue May 24, 2022 · 4 comments
Closed

imported xlsm shoud write temp xlsm for wb$open() #200

JanMarvin opened this issue May 24, 2022 · 4 comments

Comments

@JanMarvin
Copy link
Owner

macro.xlsm.zip

If some xlsm file is loaded it will not open if opened with wb$open() due to the file ending being xlsx. If xlsm is imported, if should be written as such. Might simply check if wb$vbaProject contains a binary file. (Might also be beneficial, if we ever want to be able to copy bin files from one workbook to another.) Otherwise we would have to store the file ending of the imported workbook.

# get and unzip the file
tmp <- tempdir()
setwd(tmp)
curl::curl_download("https://github.com/JanMarvin/openxlsx2/files/8765196/macro.xlsm.zip", "macro.xlsm.zip")
unzip("macro.xlsm.zip", exdir = ".")

# load and open it
wb <- wb_load("macro.xlsm")
wb$open()

Screenshot 2022-05-24 at 20 11 39

@JanMarvin
Copy link
Owner Author

That file contains a sheet with a button to press which will open a popup with the date of a string (4 lines, copy pasted from the internet ... I don't write Excel macros).

@JanMarvin
Copy link
Owner Author

Oh and it works just fine if written as wb$save("test.xlsm")

@jmbarbone
Copy link
Collaborator

We can add that vbaProject check inside $open() and then probably have a separate temp_xlsm() function (same as temp_xlsx()) for the file path. It might also be useful to have a check in $save() to give a warning when the file extension is xlsx but there's a bin file in `vbaProject.

Maybe a private$macro_enabled field would be good to simplify the checks.

@JanMarvin
Copy link
Owner Author

I've pushed a poor mans solution in #202, feel free to improve this :)

JanMarvin added a commit that referenced this issue May 26, 2022
* [R/load] guard against broken vml 

skip names assignment for conditional formatting, this was broken too.

* gsub br node

* fix tests

* partially revert conditionalFormatting change

* enable temp_xlsx to write xlsm too

* update NEWS.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants