word宏批量插入.csv格式的附件

1.ALT+F11打开宏的编译器,复制下面代码

2 F5运行,弹出对话框选择对应文件即可

vbscript 复制代码
Sub BatchInsertCSVAttachments()
    Dim fd As FileDialog
    Dim vrtSelectedItem As Variant
    Dim iconLabel As String
    
    ' 创建文件选择对话框
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
    With fd
        .Title = "请选择要插入的CSV文件(可多选)"
        .Filters.Clear
        .Filters.Add "CSV Files", "*.csv"
        .AllowMultiSelect = True ' 允许通过按住 Ctrl 或 Shift 多选
        
        If .Show = -1 Then
            ' 遍历所选文件
            For Each vrtSelectedItem In .SelectedItems
                ' 获取文件名作为图标下方的标签
                iconLabel = Dir(vrtSelectedItem)
                
                ' 插入 OLE 对象(即文件附件)
                ' DisplayAsIcon:=True 强制显示为图标
                ' IconLabel 设置为文件名,否则会显示默认的 "Worksheet" 等字样
                Selection.InlineShapes.AddOLEObject _
                    FileName:=vrtSelectedItem, _
                    LinkToFile:=False, _
                    DisplayAsIcon:=True, _
                    IconLabel:=iconLabel
                
                ' 插入一个换行符,防止图标挤在一起
                Selection.TypeParagraph
                Selection.TypeParagraph
            Next
        End If
    End With
    
    MsgBox "批量插入完成!", vbInformation
    
    ' 清理内存
    Set fd = Nothing
End Sub
相关推荐
埃博拉酱4 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
唐宋元明清21884 天前
.NET 本地Db数据库-技术方案选型
windows·c#
加号34 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
tryCbest4 天前
Windows环境下配置pip镜像源
windows·pip
呉師傅4 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
百事牛科技4 天前
保护文档安全:PDF限制功能详解与实操
windows·pdf
一个人旅程~4 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
一个假的前端男4 天前
[特殊字符] Flutter 安装完整指南 Windows—— 2026最新版
windows·flutter
倚肆5 天前
在 Windows Docker 中安装并配置 Nginx (映射 Windows 端口与路径)
windows·nginx·docker
破无差5 天前
拯救你的C盘
windows