WORDVBA批量导⼊图⽚到word并添加⽂件名
百度了很久没有到,
有部分的核⼼代码,修改了⼀下,
注:代码并⾮原创
Sub Pic()
Dim myfile As FileDialog
Set myfile = Application.FileDialog(msoFileDialogFilePicker)
With myfile
.InitialFileName = "F:\"
张学友回应给王杰下毒If .Show = -1 Then
For Each fn In .SelectedItems
Set mypic = Selection.InlineShapes.AddPicture(FileName:=fn, SaveWithDocument:=True)你是我的女朋友歌词
'按⽐例调整相⽚尺⼨世界最贵的豪车
WidthNum = mypic.Width
c = 10        '在此处修改相⽚宽,单位厘⽶
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
艺人
Selection.Text = Basename(fn)    '函数取得⽂件名
Selection.EndKey
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)    '取得⽂件名