Sub insertpic () Dim myfile as FileDialog Set myfile = Application.filedialog (msofiledialogfilepicker) with myfile . InitialFileName = "F:\" If. Show =-1 Then for each of the FN in. SelectedItems Set mypic = Selection.InlineShapes.AddPicture (FILENAME:=FN, Savewithdocument:=true) ' Proportionally adjust the photo size Widthnum = mypic. Width c = 10 ' Change the photo width here, unit cm mypic. Width = c * 28.35 mypic. Height = (c * 28.35/widthnum) * mypic. Height if Selection.start = Activedocument.content.end-1 Then ' If the cursor is at the end of the text Selection.typep Aragraph ' Add an empty segment at the end of the article Else Selection.movedown end If Selec tion. Text = Basename (fn) ' function gets the file name Selection.endkey If Selection.start = activedocument.content . End-1 then ' as the cursor at the end of the Selection.typeparagraph ' at the end of the text add an empty paragraph Else Selection.movedown End If Next fn Else End if End with Se T myfile = NothingEnd subfunction Basename (FullPath) ' Get file name 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
Batch import pictures to Word and add file names