我想在word中编个小程序判断插入word中的图片是不是指定的图片(例如d:\1.jpg)请问VBA中写代码?
答案:2 悬赏:80 手机版
解决时间 2021-02-28 02:39
- 提问者网友:容嬷嬷拿针来
- 2021-02-27 02:36
现在能通过获取图片的像素来区分是不是要求的图片,除了区分像素以外有没有别的办法来区分word中的图片是不是想要的?希望牛人给出VBA代码
最佳答案
- 五星知识达人网友:西风乍起
- 2021-02-27 03:12
直接获取插入的图片路径对比即可,或者不判断,重新进行插入图片。
全部回答
- 1楼网友:像个废品
- 2021-02-27 03:36
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会进入无响应状态。图片越多,无响应的时间越长。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯