|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 greenboater 于 2014-6-17 17:27 编辑
一个文件夹下面有N个文件夹
需要把各个文件夹里的图片都插入到word中
先插入“文件夹”的名称,格式为“1级标题”
再插入文件夹下”图片“的名称,格式为”2级标题“
最后再插入”图片“,格式为”正文“
最终效果如文件夹下的word
先感谢大侠了!!
test.rar
(706.52 KB, 下载次数: 16)
网上找着插入一个文件夹下图片的代码,供参考
- Sub 批量插入图片()
- Dim myfile As FileDialog
- Set myfile = Application.FileDialog(msoFileDialogFilePicker)
- With myfile
- .InitialFileName = "D:\111"
- If .Show = -1 Then
- For Each Fn In .SelectedItems
- Selection.Text = Basename(Fn) '这两句移到这里
- Selection.EndKey
- If Selection.Start = ActiveDocument.Content.End - 1 Then '如光标在文末
- Selection.TypeParagraph '在文末添加一空段
- Else
- Selection.MoveDown
- End If
-
- Set mypic = Selection.InlineShapes.AddPicture(FileName:=Fn, SaveWithDocument:=True)
- '按比例调整相片尺寸
- WidthNum = mypic.Width
- c = 18 '在此处修改相片宽,单位厘米
- mypic.Width = c * 28.35
- mypic.Height = (c * 28.35 / WidthNum) * mypic.Height
- If Selection.Start = ActiveDocument.Content.End - 1 Then '如光标在文末
- Selection.TypeParagraph '在文末添加一空段
- Else
- Selection.MoveDown
- End If
- Next Fn
- Else
- End If
- End With
- Set myfile = Nothing
- End Sub
- Function Basename(FullPath) '取得文件名
- Dim x, y
- Dim tmpstring
- tmpstring = FullPath
- x = Len(FullPath)
- For y = x To 1 Step -1
- If Mid(FullPath, y, 1) = "" Or _
- Mid(FullPath, y, 1) = ":" Or _
- Mid(FullPath, y, 1) = "/" Then
- tmpstring = Mid(FullPath, y + 1)
- Exit For
- End If
- Next
- Basename = Left(tmpstring, Len(tmpstring) - 4)
- End Function
复制代码
|
|