Excel VBA 一段宏在64位系统中运行会报错,32位系统运行完美,求解决方案?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Excel VBA 一段宏在64位系统中运行会报错,32位系统运行完美,求解决方案?相关的知识,希望对你有一定的参考价值。

我写了段简单的有关筛选的宏,在我自己的32位系统机器上运行没有问题,拿到64位的系统中就会报错,有什么好的解决方案吗?

针对office2007
在Windows7下删除C:\Users\charl\AppData\Roaming\Microsoft\Excel\Excel12.xlb 就好了
在WindowsXP下删除C:\Documents and Settings\你的用户名\Application Data\Microsoft\Excel\Excel12.xlb

VBA在64位下运行不完全兼容32位的代码。

参阅:
http://club.excelhome.net/thread-791290-1-1.html
参考技术A 关闭重新打开试试 参考技术B 重新下载vba程序,百度一下吧,我这里也有,找不到的话给我留个邮箱我给你发过去。

导入openpyxl模块后运行会报错

系统:window10

语言:python

模块:openpyxl

环境:pycharm

 

说明:openpyxl模块干嘛的?

用来操作excel,这里作者是用来用excel存放测试数据使用。

 

模块安装:命令pip install openpyxl

E:>pip install openpyxl
Collecting openpyxl
  Downloading https://files.pythonhosted.org/packages/95/8c/83563c60489954e5b80f9e2596b93a68e1ac4e4a730deb1aae632066d704/openpyxl-3.0.3.tar.gz (172kB)

    100% |████████████████████████████████| 174kB 9.5kB/s
Requirement already satisfied: jdcal in g:helloworldpythonlibsite-packages (from openpyxl)
Requirement already satisfied: et_xmlfile in g:helloworldpythonlibsite-packages (from openpyxl)
Building wheels for collected packages: openpyxl
  Running setup.py bdist_wheel for openpyxl ... done
  Stored in directory: C:UsersMACHENIKEAppDataLocalpipCachewheels585cae768ac132e57e75e645a151f8badac71cc0089e7225dddf76b
Successfully built openpyxl
Installing collected packages: openpyxl
Successfully installed openpyxl-3.0.3
You are using pip version 9.0.1, however version 20.1.1 is available.
You should consider upgrading via the ‘python -m pip install --upgrade pip‘ command.

 

输入操作内容:

import openpyxl

#打开文件,同级不能获取路径
excel_workbook = openpyxl.load_workbook(‘cases.xlsx‘)
print(excel_workbook)

#第二步,获取表单,类似字典操作,已经封装好了
sheet = excel_workbook[‘Sheet1‘]
print(sheet)

 

运行出现报错:

Traceback (most recent call last):
    import openpyxl
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxl\\__init__.py", line 6, in <module>
    from openpyxl.workbook import Workbook
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlworkbook\\__init__.py", line 4, in <module>
    from .workbook import Workbook
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlworkbookworkbook.py", line 7, in <module>
    from openpyxl.worksheet.worksheet import Worksheet
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlworksheetworksheet.py", line 24, in <module>
    from openpyxl.cell import Cell, MergedCell
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlcell\\__init__.py", line 3, in <module>
    from .cell import Cell, WriteOnlyCell, MergedCell
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlcellcell.py", line 27, in <module>
    from openpyxl.styles import numbers, is_date_format
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlstyles\\__init__.py", line 4, in <module>
    from .alignment import Alignment
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlstylesalignment.py", line 5, in <module>
    from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxldescriptors\\__init__.py", line 3, in <module>
    from .base import *
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxldescriptorsase.py", line 12, in <module>
    from openpyxl.utils.datetime import from_ISO8601
  File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlutilsdatetime.py", line 12, in <module>
    from jdcal import (
ModuleNotFoundError: No module named ‘jdcal‘

  

此时打开pycharm设置

技术图片

点击+号,搜索输入openpyx;

技术图片

 

再次运行:

<openpyxl.workbook.workbook.Workbook object at 0x0000025C7A2E0E88>
<Worksheet "Sheet1">

 

完美解决!

 

以上是关于Excel VBA 一段宏在64位系统中运行会报错,32位系统运行完美,求解决方案?的主要内容,如果未能解决你的问题,请参考以下文章

excel VBA(32位)在win7 64位上运行错误

如何使用 VBA 宏在 Excel 表中查找条件累积和

使用 VBA 宏在 excel 行中搜索字符串的完全匹配

Excel 的 Application.Hwnd 属性是不是可用于 64 位 VBA?

切换到 64 位 Excel 后如何修复 VBA“类型不匹配”错误

使用 Excel VBA 宏在 Word 中查找和替换页脚文本