『壹』 尋找WORD VBA高手解決WORD批量插入圖片程序的問題
Selection.Text = Basename(Fn) '這兩句移到這里
Selection.EndKey
這兩句移一下位置,其它不變。
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
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
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
『貳』 word如何批量插入圖片
這個可以先批量插入,之後採用替換的方法分頁,具體如下:
先插入-圖-來自文件-選中你想插入的全部圖,確定。
之後打開(OPEN)替換為對話框(ctrl+H),在「查找內容」那兒輸入「^g"(不含引號,下同),在替換為那兒輸入:」^&^m"。全部替換就好了。
『叄』 在word中自動插入圖片 vba代碼
Sub 批量插入圖片()
Dim myfile As FileDialog
Set myfile = Application.FileDialog(msoFileDialogFilePicker)
With myfile
.InitialFileName = "E:\工作文件" 『這里輸入你要插入圖片的目標文件夾
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 = 6 '在此處修改相片寬,單位厘米
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
執行此代碼後,彈出的選擇對話框, 全選目標文件夾下的所有圖片文件之後,點擊確定。然後靜靜的等待電腦完成處理工作,次數word會進入無響應狀態。圖片越多,無響應的時間越長。
『肆』 如何實現Word 中批量插入圖片
Sub批量添加圖片()
'程序功能:批量添加圖片宏
'作者Q:766110727
'日期:2017.06.07
'使用步驟1:word中ALT+11進入VBA宏界面;
'使用步驟2:將本段代碼從sub到endsub,全部粘到代碼框最後的空白處;
'使用步驟3:按F5執行代碼。
'說明:代碼按最直觀的邏輯寫的,也方便大家使用修改。
'OnErrorResumeNext
Dimn,圖片路徑1(),圖片路徑2(),圖片路徑3(),圖片路徑4(),圖片數量最大值
DimmyTableAsTable
'###################################################################
'#######第一部分:獲取每個文件夾下所有jpg圖片名,寫入相應數組#######
'###################################################################
n=0
圖1=Dir("I: tjbt插入圖片圖片*.jpg")
DoWhile圖1<>""
n=n+1
ReDimPreserve圖片路徑1(1Ton)
圖片路徑1(n)="I: tjbt插入圖片圖片"&圖1
圖1=Dir()
Loop
Ifn>圖片數量最大值Then圖片數量最大值=n
n=0
圖2=Dir("I: tjbt插入圖片圖片2*.jpg")
DoWhile圖2<>""
n=n+1
ReDimPreserve圖片路徑2(1Ton)
圖片路徑2(n)="I: tjbt插入圖片圖片2"&圖2
圖2=Dir()
Loop
Ifn>圖片數量最大值Then圖片數量最大值=n
n=0
圖3=Dir("I: tjbt插入圖片圖片3*.jpg")
DoWhile圖3<>""
n=n+1
ReDimPreserve圖片路徑3(1Ton)
圖片路徑3(n)="I: tjbt插入圖片圖片3"&圖3
圖3=Dir()
Loop
Ifn>圖片數量最大值Then圖片數量最大值=n
n=0
圖4=Dir("I: tjbt插入圖片圖片4*.jpg")
DoWhile圖4<>""
n=n+1
ReDimPreserve圖片路徑4(1Ton)
圖片路徑4(n)="I: tjbt插入圖片圖片4"&圖4
圖4=Dir()
Loop
Ifn>圖片數量最大值Then圖片數量最大值=n
'###################################################################
'##################第二部分:插入圖片到word表格中###################
'###################################################################
'新建一個一行兩列表格
SetmyTable=ActiveDocument.Tables.Add(Range:=ActiveDocument.Range(Start:=0,End:=0),NumRows:=1,NumColumns:=2)
'設定後續操作的目標表格為文檔的第一個表格
SetmyTable=ActiveDocument.Tables(1)
n=0
DoWhilen<圖片數量最大值
n=n+1
之前表格行數=myTable.Rows.Count
myTable.Rows.Last.Select
Selection.InsertRowsBelow4'下方插入4行
'第一行兩列,圖片序號12
myTable.Cell(Row:=之前表格行數+1,Column:=1).Range.InsertAfterText:="圖片1"
myTable.Cell(Row:=之前表格行數+1,Column:=2).Range.InsertAfterText:="圖片2"
myTable.Cell(Row:=之前表格行數+3,Column:=1).Range.InsertAfterText:="圖片3"
myTable.Cell(Row:=之前表格行數+3,Column:=2).Range.InsertAfterText:="圖片4"
'第二行兩列,插入圖片並設置圖片大小
myTable.Cell(Row:=之前表格行數+2,Column:=1).Range.InlineShapes.AddPictureFileName:=_
圖片路徑1(n),LinkToFile:=False,SaveWithDocument:=True
myTable.Cell(Row:=之前表格行數+2,Column:=2).Range.InlineShapes.AddPictureFileName:=_
圖片路徑2(n),LinkToFile:=False,SaveWithDocument:=True
myTable.Cell(Row:=之前表格行數+4,Column:=1).Range.InlineShapes.AddPictureFileName:=_
圖片路徑3(n),LinkToFile:=False,SaveWithDocument:=True
myTable.Cell(Row:=之前表格行數+4,Column:=2).Range.InlineShapes.AddPictureFileName:=_
圖片路徑4(n),LinkToFile:=False,SaveWithDocument:=True
Loop
ActiveDocument.Tables(1).Rows(1).Delete'剛開始建的表格中第一行是空行,刪掉
'###################################################################
'######################第三部分:圖片格式處理#######################
'###################################################################
'統一設置圖片長寬,美化文檔。這里會卡好久時間,按需要是否添加本段代碼
Forn=1ToActiveDocument.InlineShapes.Count
ActiveDocument.InlineShapes(n).Height=210'設置高度
ActiveDocument.InlineShapes(n).Width=110'設置寬度
Nextn
EndSub
『伍』 怎樣在WORD中批量插入圖片
方法一:
1、單擊插入---->圖片,如圖所示;
2、在彈出「插入圖片」對話框中選擇存放圖片的位置,此時按住
ctrl
鍵,你就可以用滑鼠選擇多張圖片了;或者你也可以按 shift
鍵,然後單擊選中一張圖片,再單擊另一張圖片,則自動選中了這兩張圖片為對角線的矩形范圍內的所有圖片;或者直接按快捷鍵 ctrl+a
全選,全部選中。最後「插入」即可,如圖所示。
方法二:
1、打開存放圖片的位置,然後選中你的插入的全部圖片;
2、在按下滑鼠右鍵,選擇「復制」;
3、word文檔中,按下滑鼠再按下右鍵,選擇「粘貼」,即可快速想插入的多個圖片。
『陸』 word文檔如何批量插入圖片
您好,方法
1、首先我們打開word文檔,現在文檔中是空白的,沒有文字也沒有圖片。
2、我們在上方點擊【插入】-【圖片】選擇【本地圖片】。
3、我們在圖片文件夾里,把所有的圖片一起選中,點擊【打開】。
4、發現插入進行來的圖片大小一樣,
5、我們拖動圖片邊上的四個點,即可調整圖片大小,
6、因為圖片的高度問題,這里一頁紙上默認顯示兩張圖片。把所有的圖片寬度調整成一樣的大小就完成了。
『柒』 利用VBA如何將批量圖片導入WORD的指定表格格式里
將excel表格中的數據批量插入到word中的操作方法:
1、單擊插入----對象按鈕;
2、彈出插入對話框對話框,選擇由文件創建對話框,單擊瀏覽按鈕;
3、彈出瀏覽對話框,選擇需要插入有Excel文件;
4、單擊插入按鈕即可。
註:
(1)若選中鏈接到文件,源文件修改,Word中的表格也隨之改變;
(2)若選中顯示為圖片,則以圖標的形式插入到Word,雙擊可以打開其源文件。
『捌』 word vba 插入圖片
Sub 批量插入圖片()
Dim myfile As FileDialog
Set myfile = Application.FileDialog(msoFileDialogFilePicker)
With myfile
.InitialFileName = "E:\工作文件" 『這里輸入你要插入圖片的目標文件夾
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 = 6 '在此處修改相片寬,單位厘米
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
執行此代碼後,彈出的選擇對話框, 全選目標文件夾下的所有圖片文件之後,點擊確定。然後靜靜的等待電腦完成處理工作,次數word會進入無響應狀態。圖片越多,無響應的時間越長。