|
学习其他人的代码,根据自己需要,修改了一下
利用vba在word表格内插入图片,为什么执行不下去?代码如下
Sub 插入图片()
Dim fd As FileDialog, arr(0 To 1), brr(0 To 1)
Set fd = Application.FileDialog(msoFileDialogFolderPicker) '选择图片所在文件夹
fd.Show
12345
tupianming = Dir(fd.SelectedItems(1) & "\*.*") '读取图片名称
'MsgBox (tupianming)
Do
i = s + 1
vv = VBA.Split(tupianming, ".")(0)
' MsgBox (vv)
On Error Resume Next
biaogeming = Replace(ActiveDocument.Tables(i).Cell(1, 2).Range, " ", "") '读取表格中第一行每二列单元格的名称
biaogeming = Left(biaogeming, Len(biaogeming) - 1)
' MsgBox (biaogeming)
'现在的问题就是下面这个判断始终不能运行,不管是不是名字相同,都会跳出????
If biaogeming = vv Then '判断图片名称和单元格名称是否一致
ActiveDocument.Tables(i).AllowAutoFit = False
ActiveDocument.Tables(i).Cell(1, 7).Range.InlineShapes.AddPicture fd.SelectedItems(1) & "/" & tupianming
' fd.SelectedItems (1) & "/" & nm
s = s + 1
GoTo 12345
If i = ActiveDocument.Tables.Count Then
Exit Do
End If
End If
tupianming = Dir
Loop Until tupianming = ""
|
|