如何批量插入多個圖片到您的Word文檔

立即分享:

在本文中,我們想為您提供一種將多張圖片批量插入Word文檔的方法。

在Word中處理圖片時,您會感到很舒服。 將圖片插入文檔後,可能必須手動調整其大小或在其周圍輸入其名稱。 如何使用宏自動執行任務?批量插入多張圖片到您的Word文檔

我們將向您呈現的宏具有以下功能:

  1. 首先,它會在每頁中插入您指定的確切圖片數量。
  2. 其次,在每張圖片下方插入名稱。
  3. 第三,它會根據您輸入的尺寸編號來調整圖片的尺寸。

現在,讓我們看看如何使其工作。

批量插入多張圖片到文檔

  1. 首先,安排所有圖片插入同一文件夾下。
  2. 然後按“ Alt + F11”以在Word中調用VBA編輯器。
  3. 接下來單擊“普通”項目。
  4. 然後在菜單欄上,單擊“插入”。
  5. 然後在下拉菜單上選擇“模塊”。單擊“常規”->單擊“插入”->單擊“模塊”
  6. 雙擊打開模塊並粘貼以下代碼:
Sub InsertSpecificNumberOfPictureForEachPage()
  Dim StrFolder As String
  Dim strFile As String
  Dim objDoc As Document
  Dim dlgFile As FileDialog
  Dim objInlineShape As InlineShape
  Dim nResponse As Integer
  Dim strPictureNumber As Integer
  Dim strPictureSize As String
  Dim n As Integer  

  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
  
  With dlgFile
    If .Show = -1 Then
      StrFolder = .SelectedItems(1) & "\"
    Else
      MsgBox ("No Folder is selected!")
      Exit Sub
    End If
  End With

  strFile = Dir(StrFolder & "*.*", vbNormal)
  strPictureNumber = InputBox("Input the number of the picture for each page", "Picture Number", "For exemple: 1")
  n = 1  

  While strFile <> ""
    Selection.InlineShapes.AddPicture FileName:=StrFolder & strFile, LinkToFile:=False, SaveWithDocument:=True
    Selection.TypeParagraph
    Selection.Collapse Direction:=wdCollapsEnd
    Selection.TypeText Text:=Left(strFile, InStrRev(strFile, ".") - 1)
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    If ActiveDocument.InlineShapes.Count = strPictureNumber * n Then
      Selection.InsertNewPage
      Selection.TypeBackspace
      n = n + 1
    End If
    Selection.TypeParagraph
    strFile = Dir()
  Wend

  For Each objInlineShape In ActiveDocument.InlineShapes
    objInlineShape.Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  Next objInlineShape

  nResponse = MsgBox("Do you want to resize all pictures?", 4, "Resize Picture")
  If nResponse = 6 Then
    strPictureSize = InputBox("Input the height and width of the picture, seperated by comma", "Height and Width", "For exemple:500,500")
    For Each objInlineShape In ActiveDocument.InlineShapes
      objInlineShape.Height = Split(strPictureSize, ",")(0)
      objInlineShape.Width = Split(strPictureSize, ",")(1)
    Next objInlineShape
  End If
End Sub
  1. 然後單擊“運行”或單擊“ F5”。粘貼代碼->單擊“運行”
  2. 運行宏時,將彈出“瀏覽”窗口。 只需在步驟1中選擇保存圖片的文件夾,然後單擊“確定”即可。選擇一個文件夾->單擊“確定”
  3. 接下來,在“圖片編號”框中,輸入一個數字,該數字表示單個頁面中所需的圖片總數。 然後單擊“確定”繼續。輸入數字->單擊“確定”
  4. 在“調整圖片大小”框中,單擊“是”調整所有圖片的大小,單擊“否”取消它。單擊“是”或“否”在“調整圖片大小”框中
  5. 現在,在“高度和寬度”框中,輸入值並使用逗號分隔。 記住先輸入高度,然後再輸入寬度。 逗號後沒有空格。
  6. 同樣,單擊“確定”繼續。輸入高度和寬度值,並使用逗號分隔->單擊“確定”

現在,一頁中有2張圖片,每張圖片下方都有其名稱。 結果如下:調整圖片大小

密切關注數據完整性

始終存在丟失數據或以某種方式破壞數據的風險。 這意味著我們必須定期檢查數據完整性。 一旦發現任何跡象 字損,恢復數據的最佳方法是獲得修復工具。

作者簡介:

陳薇薇(Vera Chen)是 DataNumen,Inc.是數據恢復技術的全球領導者,包括 Excel恢復 以及 pdf 維修軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM

立即分享:

評論被關閉。