# Excel Vibe Coder

> Excel VBA 智能编程助手。通过自然语言描述需求，自动生成、注入、执行 VBA 代码到 Excel 工作簿中。支持创建新模块、修改已有代码、调用用户现有宏、调试和优化 VBA 代码。默认保留所有注入的模块供用户手动复用和调试，实现 Excel 版本的 Vibe Coding 体验。

- **Type:** Skill
- **Install:** `agentstack add skill-parry-123-excel-vibe-coder-skill-excel-vibe-coder-skill`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [parry-123](https://agentstack.voostack.com/s/parry-123)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [parry-123](https://github.com/parry-123)
- **Source:** https://github.com/parry-123/excel-vibe-coder-skill

## Install

```sh
agentstack add skill-parry-123-excel-vibe-coder-skill-excel-vibe-coder-skill
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Excel Vibe Coder

Excel VBA 智能编程助手，让 Excel 变成可编程的智能工作簿。

> ⚠️ **执行方式警告**：本技能必须使用 `write_file` + `run_shell_command` 的方式执行Python代码，**严禁**使用 `python -c "..."` 内联代码方式。

## 核心工具

本 skill 提供 `vba_manager.py` 工具脚本，封装了所有 VBA 操作功能。

### 工具位置
```
{SKILL_DIR}\tools\vba_manager.py
```

### 使用方法

通过 `run_shell_command` 调用，命令格式：
```bash
python vba_manager.py  [参数...]
```

返回结果为 **JSON 格式**，包含 `success` 字段和具体数据。

---

## 命令参考

### 1. list - 列出所有 VBA 模块

**用途**：查看工作簿中有哪些模块

**命令**：
```bash
python vba_manager.py list ""
```

**示例**：
```python
run_shell_command({
    "command": 'python vba_manager.py list "D:\\test.xlsm"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

**返回**：
```json
{
  "success": true,
  "file": "test.xlsm",
  "modules": [
    {"name": "Module1", "type": "模块", "type_id": 1, "lines": 50},
    {"name": "Sheet1", "type": "文档", "type_id": 100, "lines": 10}
  ]
}
```

---

### 2. read - 读取模块代码

**用途**：查看已有模块的代码内容

**命令**：
```bash
python vba_manager.py read "" ""
```

**示例**：
```python
run_shell_command({
    "command": 'python vba_manager.py read "D:\\test.xlsm" "Module1"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

**返回**：
```json
{
  "success": true,
  "module": "Module1",
  "code": "Sub Hello()\n    MsgBox \"Hello\"\nEnd Sub"
}
```

---

### 3. write - 写入/覆盖模块

**用途**：创建新模块或覆盖已有模块

**命令**：
```bash
python vba_manager.py write "" "" ""
```

**示例**：
```python
# 先生成代码文件
write_file({
    "file_path": "D:\\AgentWorkspace\\temp\\mycode.bas",
    "content": '''
Sub HelloFromAI()
    MsgBox "Hello from AI!"
End Sub
'''
})

# 然后写入到 Excel
run_shell_command({
    "command": 'python vba_manager.py write "D:\\test.xlsm" "AiModule" "D:\\AgentWorkspace\\temp\\mycode.bas"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

**返回**：
```json
{
  "success": true,
  "module": "AiModule",
  "lines": 3
}
```

---

### 4. delete - 删除模块

**用途**：删除指定模块

**命令**：
```bash
python vba_manager.py delete "" ""
```

**示例**：
```python
run_shell_command({
    "command": 'python vba_manager.py delete "D:\\test.xlsm" "TempModule"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

---

### 5. run - 运行宏

**用途**：执行指定的 VBA 宏

**命令**：
```bash
python vba_manager.py run "" "" [参数1] [参数2] ...
```

**示例**：
```python
# 无参数
run_shell_command({
    "command": 'python vba_manager.py run "D:\\test.xlsm" "AiModule.HelloFromAI"',
    "cwd": "{SKILL_DIR}\\tools"
})

# 带参数
run_shell_command({
    "command": 'python vba_manager.py run "D:\\test.xlsm" "Module1.AddNumbers" "10" "20"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

**返回**：
```json
{
  "success": true,
  "macro": "AiModule.HelloFromAI",
  "result": null
}
```

---

### 6. export - 导出模块

**用途**：将模块导出为 .bas/.cls/.frm 文件

**命令**：
```bash
python vba_manager.py export "" "" ""
```

**示例**：
```python
run_shell_command({
    "command": 'python vba_manager.py export "D:\\test.xlsm" "Module1" "D:\\backup\\module1.bas"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

---

### 7. import - 导入模块

**用途**：从文件导入模块到 Excel

**命令**：
```bash
python vba_manager.py import "" "" [新名称]
```

**示例**：
```python
# 保持原名
run_shell_command({
    "command": 'python vba_manager.py import "D:\\test.xlsm" "D:\\code\\utils.bas"',
    "cwd": "{SKILL_DIR}\\tools"
})

# 重命名
run_shell_command({
    "command": 'python vba_manager.py import "D:\\test.xlsm" "D:\\code\\utils.bas" "MyUtils"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

---

## 完整工作流示例

### 场景：AI 生成代码并运行

```python
# Step 1: 生成 VBA 代码
write_file({
    "file_path": "D:\\AgentWorkspace\\temp\\generated_code.bas",
    "content": '''
Sub ProcessData()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")
    
    ' 统计 A 列非空单元格
    Dim count As Long
    Dim cell As Range
    
    For Each cell In ws.Range("A1:A100")
        If cell.Value <> "" Then
            count = count + 1
        End If
    Next cell
    
    MsgBox "A列共有 " & count & " 个非空单元格", vbInformation
End Sub
'''
})

# Step 2: 写入到 Excel
run_shell_command({
    "command": 'python vba_manager.py write "D:\\data\\report.xlsm" "DataProcessor" "D:\\AgentWorkspace\\temp\\generated_code.bas"',
    "cwd": "{SKILL_DIR}\\tools"
})

# Step 3: 运行宏
run_shell_command({
    "command": 'python vba_manager.py run "D:\\data\\report.xlsm" "DataProcessor.ProcessData"',
    "cwd": "{SKILL_DIR}\\tools"
})
```

---

## 错误处理

所有命令返回 JSON 格式，通过 `success` 字段判断：

```python
import json

result = run_shell_command({...})
data = json.loads(result)

if data["success"]:
    print(f"✅ 成功: {data}")
else:
    print(f"❌ 失败: {data['error']}")
```

---

## 前置要求

1. **Excel 设置**：
   - 文件 → 选项 → 信任中心 → 信任中心设置
   - 宏设置 → 勾选 **"信任对 VBA 工程对象模型的访问"**

2. **文件格式**：
   - 必须使用 `.xlsm` 格式（启用宏的工作簿）
   - `.xlsx` 无法保存 VBA 代码

3. **依赖库**：
   ```bash
   pip install pywin32
   ```

---

## 模块类型说明

| type_id | 类型 | 说明 |
|---------|------|------|
| 1 | 模块 | 标准代码模块（最常用） |
| 2 | 类模块 | 面向对象类定义 |
| 3 | 窗体 | 用户窗体（带界面） |
| 100 | 文档 | Sheet/Workbook 代码 |

---

## 最佳实践

1. **模块命名**：使用英文或拼音，不含空格
2. **代码备份**：重要操作前先用 `export` 备份
3. **错误处理**：生成的代码建议加 `On Error` 处理
4. **保存习惯**：`write` 命令会自动保存，但重要操作后建议手动确认

---

## 用户提示语

当用户说以下话时触发本 skill：
- "帮我写个 VBA 宏..."
- "在这个 Excel 里添加功能..."
- "运行我的宏..."
- "读取/修改 VBA 代码..."
- "导出 VBA 模块..."

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [parry-123](https://github.com/parry-123)
- **Source:** [parry-123/excel-vibe-coder-skill](https://github.com/parry-123/excel-vibe-coder-skill)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-parry-123-excel-vibe-coder-skill-excel-vibe-coder-skill
- Seller: https://agentstack.voostack.com/s/parry-123
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
