feat: VBA Automated Testing and Precise Error Reporting System
Implement a comprehensive VBA testing framework that provides precise line-by-line error reporting through code weaving technology. Core Features: - CodeWeaver: Injects line number labels and error handling into VBA code - LoggerInjector: Manages TestLogger module for capturing test results - TestRunner: Orchestrates Excel lifecycle and test execution - Command-line interface supporting single and batch testing Key Capabilities: - Captures exact line numbers where errors occur - Displays source code context for error locations - Non-invasive testing (original files unchanged) - Batch testing support with detailed summaries Components: - vba_test_runner.py: Main framework implementation - demo.xlsm: Demo Excel file with test procedures - create_demo.py: Script to generate demo files - check_vba_access.py: VBA access permission checker Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
54
check_vba_access.py
Normal file
54
check_vba_access.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
检查 Excel VBA 项目访问设置
|
||||
"""
|
||||
|
||||
import winreg
|
||||
import os
|
||||
|
||||
def check_vba_project_access():
|
||||
"""检查是否启用了对 VBA 工程对象模型的访问"""
|
||||
|
||||
# Excel 版本的注册表路径
|
||||
excel_versions = [
|
||||
r"Software\Microsoft\Office\16.0\Excel\Security",
|
||||
r"Software\Microsoft\Office\15.0\Excel\Security",
|
||||
r"Software\Microsoft\Office\14.0\Excel\Security",
|
||||
]
|
||||
|
||||
print("Checking Excel VBA Project Access Settings...\n")
|
||||
|
||||
found = False
|
||||
for version_path in excel_versions:
|
||||
try:
|
||||
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, version_path)
|
||||
access_value, _ = winreg.QueryValueEx(key, "AccessVBOM")
|
||||
winreg.CloseKey(key)
|
||||
|
||||
if access_value == 1:
|
||||
print(f"[OK] VBA Project Access is ENABLED in {version_path}")
|
||||
found = True
|
||||
else:
|
||||
print(f"[WARN] VBA Project Access is DISABLED in {version_path}")
|
||||
except FileNotFoundError:
|
||||
continue
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to check {version_path}: {e}")
|
||||
|
||||
if not found:
|
||||
print("\n[INFO] VBA Project Access settings not found in registry.")
|
||||
print("You may need to enable it manually in Excel.")
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("How to Enable VBA Project Access in Excel:")
|
||||
print("="*60)
|
||||
print("1. Open Excel")
|
||||
print("2. Go to File > Options > Trust Center")
|
||||
print("3. Click 'Trust Center Settings...'")
|
||||
print("4. Go to 'Macro Settings'")
|
||||
print("5. Check the box: 'Trust access to the VBA project object model'")
|
||||
print("6. Click OK to save changes")
|
||||
print("7. Restart Excel")
|
||||
print("="*60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_vba_project_access()
|
||||
Reference in New Issue
Block a user