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
相关推荐
武藤一雄1 天前
C# 关于多线程如何实现需要注意的问题(持续更新)
windows·后端·microsoft·c#·.net·.netcore·死锁
coding消烦员2 天前
在 Windows 内网搭建 Git 仓库:共享普通仓库 vs 中心 bare 仓库
windows·git
薛定谔的猫-菜鸟程序员2 天前
从零到一:用Electron打造专业的Markdown转Word桌面应用。
javascript·electron·word
wtsolutions2 天前
Sheet-to-Doc高级功能:循环占位符的使用技巧
json·word·wtsolutions·sheet-to-doc
xiaoliuliu123452 天前
IE8-WindowsXP-x86-CHS_23253_BDdl.exe 安装步骤(XP 32位简体中文版)
windows
百事牛科技2 天前
文件不想再加密了?取消Word 打开密码的方法
windows·word
love530love2 天前
EPGF 新手教程 13在 PyCharm(中文版 GUI)中创建 Hatch 项目环境,并把 Hatch 做成“项目自包含”(工具本地化为必做环节)
开发语言·ide·人工智能·windows·python·pycharm·hatch
峰上踏雪2 天前
Go(Golang)Windows 环境配置关键点总结
开发语言·windows·golang·go语言
lusasky2 天前
在Windows上编译、安装Rust
开发语言·windows·rust
麻辣长颈鹿Sir2 天前
CMAKE指令集
linux·运维·windows·cmake·cmake指令集