Skip to content

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 when saving file on "xlwings vba edit" command #2654

@ViniciusLCLima

Description

@ViniciusLCLima

I've installed xlwings through the command "pip install xlwings".
I've started running "xlwings vba edit" through the powershell terminal in VSCODE.
I typed "Y" when presented the file that would be affected and prompted to proceed.
When I open the bas and frm files to edit, some characters are substituted by question marks in vscode though.

Image

When I save the files, the question marks go to the excel workbook, substituting characters like "õ", "ú", "é", "ç", which is not desired.

I then tried to change the encoding in vscode to "windows 1252". The characters were fine after this, but after trying to save, i got the following error:

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\Vinícius Lima\AppData\Local\Programs\Python\Python314\Scripts\xlwings.exe_main
.py", line 6, in
sys.exit(main())
~~~~^^
File "C:\Users\Vinícius Lima\AppData\Local\Programs\Python\Python314\Lib\site-packages\xlwings\cli.py", line 1302, in main
args.func(args)
~~~~~~~~~^^^^^^
File "C:\Users\Vinícius Lima\AppData\Local\Programs\Python\Python314\Lib\site-packages\xlwings\cli.py", line 872, in vba_edit
vba_code = f.readlines()
File "", line 325, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 1232: invalid continuation byte

How can it be solved?

I'm using Windows 11 Pro and Office LTSC Professional Plus 2021

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions