Implement VBA-based Excel tool for automatic classification of pressure gauge model codes into 9 product categories. Features: - GaugeClassifier class with parsing and classification logic - MainModule for Excel I/O with bulk array operations - TestModule with comprehensive test suite (12 test cases) - Complete documentation (README, INSTALL, algorithm guide) Categories: 喷涂产品, 卫生型隔膜表, 隔膜表, 差压表, 膜盒压力表, 精密压力表, 电接点压力表, 常规表, 其他 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
6.6 KiB
6.6 KiB
Installation Guide - BLDI Pressure Gauge Classification Tool
Quick Installation (5 Steps)
Step 1: Prepare Excel File
- Create a new Excel workbook or open existing one
- Save as Excel Macro-Enabled Workbook (.xlsm)
- File → Save As
- Select "Excel Macro-Enabled Workbook (*.xlsm)"
Step 2: Open VBA Editor
- Press
Alt + F11(or Developer → Visual Basic)
Step 3: Import GaugeClassifier Class
- In VBA Editor: File → Import File...
- Navigate to:
VBA/ClassModules/GaugeClassifier.cls - Click Open
- Verify in Project Explorer (Ctrl+R) under "Class Modules"
Step 4: Import MainModule
- File → Import File...
- Navigate to:
VBA/Modules/MainModule.bas - Click Open
- Verify under "Modules"
Step 5: Import TestModule
- File → Import File...
- Navigate to:
VBA/Modules/TestModule.bas - Click Open
- Verify under "Modules"
Step 6: Verify Installation
- Press
Alt + F8to open Macro dialog - You should see:
RunClassificationRunClassificationOnSelectionClearClassificationsTestClassifierLogicTestParsingMethodsTestPerformanceTestSingleInput
Project Structure After Import
VBAProject (YourWorkbookName)
├── Class Objects
│ └── GaugeClassifier
├── Modules
│ ├── MainModule
│ └── TestModule
└── Sheets (your worksheets)
Running Tests
1. Basic Classification Test
- Open Immediate Window:
Ctrl + G - Run: Press
F5in TestModule or useAlt + F8→TestClassifierLogic - Check Immediate Window for results
Expected output:
========================================
GaugeClassifier Test Results
========================================
[✓ PASS] Test 1: 喷涂产品
[✓ PASS] Test 2: 卫生型隔膜表
[✓ PASS] Test 3: 喷涂产品
...
========================================
Summary:
Total: 12
Passed: 12
Failed: 0
========================================
2. Performance Test
- Run
TestPerformancefrom Macro dialog - Should process 1000 records in < 1 second
First Use
1. Prepare Data
In your worksheet:
- Column A: Model codes (from A2 downward)
- Column B: Will contain classifications (auto-generated)
Example:
A B
┌────────────────────────────────────────────────────┐
1 │ 型号代码 │ 产品分类 │
├────────────────────────────────────────────────────┤
2 │ PYTH-100.A0.531.M201.M02|BP-088.2312...|FBP-...│
3 │ Y-040.Z0.200.M104.M07|BP-037.1007.M07.0A2 │
4 │ YX-100.A0.200.M204.M16.H4|BP-098.0088... │
└────────────────────────────────────────────────────┘
2. Run Classification
- Click anywhere in your data sheet
- Press
Alt + F8 - Select
RunClassification - Click Run
3. View Results
Classifications appear in column B automatically.
Alternative Installation: Manual Copy
If import doesn't work, create modules manually:
Create GaugeClassifier.cls
- In VBA Editor: Insert → Class Module
- Name it:
GaugeClassifier(in Properties window, F4) - Paste contents from
VBA/ClassModules/GaugeClassifier.cls
Create MainModule.bas
- Insert → Module
- Name it:
MainModule - Paste contents from
VBA/Modules/MainModule.bas
Create TestModule.bas
- Insert → Module
- Name it:
TestModule - Paste contents from
VBA/Modules/TestModule.bas
Troubleshooting
Import Errors
Error: "File not found"
- Verify file paths are correct
- Use full path if needed:
C:\Users\Administrator\Desktop\生产周期核对\VBA\...
Error: "Invalid file format"
- Ensure you're importing
.clsand.basfiles, not source code files - Check files aren't open in another program
Runtime Errors
Error: "Compile error: User-defined type not defined"
- Make sure
GaugeClassifieris imported as a Class Module, not standard module - Delete and re-import as Class Module
Error: "Runtime error 1004"
- Check macro security settings:
- File → Options → Trust Center → Trust Center Settings
- Macro Settings → Enable all macros (or add to Trusted Locations)
Error: "Object variable not set"
- Ensure you're running from a worksheet, not VBA Editor
- Check that
GaugeClassifierclass module exists
Missing Macros in Dialog
If macros don't appear in Alt + F8:
- Check they're in standard modules (not class modules)
- Ensure module names are correct:
MainModule,TestModule - Try closing and reopening workbook
- Check Excel Trust Center settings
Security Settings
Enable Macros (One-time)
- File → Options → Trust Center → Trust Center Settings
- Macro Settings
- Select: Enable all macros (use with caution) OR Disable all macros with notification (recommended)
- If using notification: Click "Enable Content" when opening workbook
Add to Trusted Location (Recommended)
- File → Options → Trust Center → Trust Center Settings
- Trusted Locations
- Click "Add new location"
- Browse to:
C:\Users\Administrator\Desktop\生产周期核对\ - Check "Subfolders of this location are also trusted"
- Click OK
Configuration
Change Input/Output Columns
Edit MainModule.bas:
' Current: Read from A, write to B
Set dataRange = ws.Range("A2:A" & lastRow) ' Change input column
ws.Range("B2:B" & (lastRow)).Value = outputData ' Change output column
Add Custom Categories
Edit GaugeClassifier.cls in the Classify function.
Uninstallation
- Open VBA Editor (
Alt + F11) - In Project Explorer:
- Right-click
GaugeClassifier→ Remove File - Right-click
MainModule→ Remove File - Right-click
TestModule→ Remove File
- Right-click
- Save workbook
Verification Checklist
- Workbook saved as
.xlsm - All three modules imported successfully
GaugeClassifieris a Class ModuleMainModuleandTestModuleare standard Modules- Macros visible in
Alt + F8dialog TestClassifierLogicruns successfully with all tests passing- Can classify sample data in worksheet
Support
If issues persist:
- Check Excel version (requires Excel 2007 or later)
- Verify Windows security permissions
- Try on a new blank workbook
- Consult README.md for additional documentation