在word中自动插入图片 vba,这是一段代码 50
OptionExplicitSubInsertJGP()DimmyPictureFolderAsString,aParAsParagraph,KeyPostionAsLo...
Option Explicit
Sub InsertJGP()
Dim myPictureFolder As String, aPar As Paragraph, KeyPostion As Long
Dim PictureName As String, myRange As Range
On Error Resume Next
Application.ScreenUpdating = False
myPictureFolder = "H:\照片\107#-2600+668.5通道桥"
With ActiveDocument
For Each aPar In .Paragraphs
If VBA.InStr(aPar.Range, "检查图片") = 1 Then
KeyPostion = VBA.InStr(aPar.Range, ":")
Set myRange = .Range(aPar.Range.Start + KeyPostion, aPar.Range.End - 1)
PictureName = VBA.Trim(myRange)
myRange.Delete
Debug.Print PictureName
If Dir(myPictureFolder & PictureName, vbDirectory) <> "" Then
.InlineShapes.AddPicture myPictureFolder & PictureName, , , myRange
End If
End If
Next
End With
Application.ScreenUpdating = True
End Sub
Sub InsertJPG2()
Dim myPictureFolder As String, aPar As Paragraph, KeyPostion As Long, myRange As Range
On Error Resume Next
myPictureFolder = "H:\照片\107#-2600+668.5通道桥"
With ActiveDocument
For Each aPar In .Paragraphs
If VBA.InStr(aPar.Range, "检查图片") = 1 Then KeyPostion = VBA.InStr(aPar.Range, ":")
Set myRange = .Range(aPar.Range.Start + KeyPostion, aPar.Range.End - 1)
myRange = "INCLUDEPICTURE """ & myPictureFolder & myRange & """"
.Fields.Add myRange, wdFieldEmpty, , False myRange.Fields(1).Update
End If
Next
End
With Application.ScreenUpdating = True
End Sub
要实现的意义是,在word中键入“检查图片IMG-8802.jpg”如果在指定的文件夹中有这个文件的话就自动把照片插入进去,需要一次性插入 100左右个图片 展开
Sub InsertJGP()
Dim myPictureFolder As String, aPar As Paragraph, KeyPostion As Long
Dim PictureName As String, myRange As Range
On Error Resume Next
Application.ScreenUpdating = False
myPictureFolder = "H:\照片\107#-2600+668.5通道桥"
With ActiveDocument
For Each aPar In .Paragraphs
If VBA.InStr(aPar.Range, "检查图片") = 1 Then
KeyPostion = VBA.InStr(aPar.Range, ":")
Set myRange = .Range(aPar.Range.Start + KeyPostion, aPar.Range.End - 1)
PictureName = VBA.Trim(myRange)
myRange.Delete
Debug.Print PictureName
If Dir(myPictureFolder & PictureName, vbDirectory) <> "" Then
.InlineShapes.AddPicture myPictureFolder & PictureName, , , myRange
End If
End If
Next
End With
Application.ScreenUpdating = True
End Sub
Sub InsertJPG2()
Dim myPictureFolder As String, aPar As Paragraph, KeyPostion As Long, myRange As Range
On Error Resume Next
myPictureFolder = "H:\照片\107#-2600+668.5通道桥"
With ActiveDocument
For Each aPar In .Paragraphs
If VBA.InStr(aPar.Range, "检查图片") = 1 Then KeyPostion = VBA.InStr(aPar.Range, ":")
Set myRange = .Range(aPar.Range.Start + KeyPostion, aPar.Range.End - 1)
myRange = "INCLUDEPICTURE """ & myPictureFolder & myRange & """"
.Fields.Add myRange, wdFieldEmpty, , False myRange.Fields(1).Update
End If
Next
End
With Application.ScreenUpdating = True
End Sub
要实现的意义是,在word中键入“检查图片IMG-8802.jpg”如果在指定的文件夹中有这个文件的话就自动把照片插入进去,需要一次性插入 100左右个图片 展开
2个回答
展开全部
你的第1段代码可以插入图片啊,有什么问题?
第2段的话,把倒数第2行的with移到上一行end 的后面。
倒数第6行的 ,,Flase 改成,Flash,(逗号移到flash后面)
VBA不是很熟,希望能帮到你。
第2段的话,把倒数第2行的with移到上一行end 的后面。
倒数第6行的 ,,Flase 改成,Flash,(逗号移到flash后面)
VBA不是很熟,希望能帮到你。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |