导航:首页 > 文字图片 > vba批量图片如何导入word

vba批量图片如何导入word

发布时间:2023-02-19 08:34:05

1. 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会进入无响应状态。图片越多,无响应的时间越长。

2. 关于图片批量导入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会进入无响应状态。图片越多,无响应的时间越长。

3. 大神,图片按照规律批量导入Word指定位置,如何用VBA实现

看我的头像,找到我的主页,联系上我。
网络很垄断,很霸道,我的任何回答,它就都直接屏蔽删除!

4. 怎么编VBA把图片放到WORD里并附上该图的名称(50分)

要从两个方面考虑:
1、如何把现有文档中的图片导出?这个代码片断可以参考一下:
Set ImageStream = CreateObject("ADODB.Stream")
With ImageStream
.Type = 1
.Open
.Write ActiveDocument.InlineShapes(1).Range.EnhMetaFileBits
.SaveToFile "d:\Temp\Output.bmp"
.Close
End With
Set ImageStream = Nothing

2、如何把已经到处的图片导入到新文档中?这个函数调用可以参考一下:
ActiveDocument.InlineShapes.AddPicture

如果还是不明白的话,请补充提问。

_____
补充:
请问楼主你运行那个代码片断得到的*完整*错误信息是什么?报错的时候,系统一般会把光标移动到出错的那行代码上,你看到的是哪一行代码出错呢?
我看你贴上来的代码应该是没有什么语法上的错误,“Exit For”的确是不应该要的,但那也不是语法错误啊。

5. 用VBA转PDF为图片插入的word中

能,需要传两个参数,word路径和pdf路径。

代码可以做成wsf文件,通过C语言或者java调用

<job id="wtop">

<reference guid="{00020905-0000-0000-C000-000000000046}" comment="MSWord 2000 tag library,under HKEY_CLASSES_ROOTTypeLib"/>

<script language="VBScript">

Option Explicit

Dim Home_file

Dim outdoc_file

'If WScript.Arguments.Count < 2 Then

' MsgBox "Usage: t1 <Home_file> <outdoc_file> "

' WScript.Quit

'End If

Home_file = WScript.Arguments(0)

outdoc_file = WScript.Arguments(1)

Dim WordApp

Set WordApp = CreateObject("Word.Application")

With WordApp

.Visible = False '设置word为可见

With .Options

.CheckSpellingAsYouType = False '不检查拼写

.CheckGrammarAsYouType = False '不检查语法

End With

'打开模板文件

.Documents.Open(Home_file)

.Documents(1).Activate '激活文档

Dim doc

Set doc = .ActiveDocument '得到这个使用中的文件

doc.ExportAsFixedFormat outdoc_file, 17, False, 0, 0, 1, 1, 0, True, True, 0, True, True, False

doc.Close False

With .Options

.CheckSpellingAsYouType = True

.CheckGrammarAsYouType = True

End With

.Quit

End With

</script>

</job>

6. 如何用VBA把Excel中的数据和文件夹中的图片放入到Word文档中

把Excel中的数据和文件夹中的图片放入到Word文档中方法:

1、打开EXCEL文件,复制单元格数据区域。

阅读全文

与vba批量图片如何导入word相关的资料

热点内容
衣服图片简单图 浏览:899
长脸适合什么短的发型图片 浏览:546
冬天衣服裤子图片卡通 浏览:392
唯美图片大全高清伤感女生 浏览:138
160斤的女生图片自拍 浏览:192
我爱阅读手抄报简单漂亮图片 浏览:357
越南企业高清图片 浏览:158
松鼠卡通图片可爱趴着 浏览:275
漂亮夏季衣服图片 浏览:399
初中生书包女生图片 浏览:763
wps如何将制作好的内容做成图片 浏览:197
文档图片显示很乱如何调整 浏览:557
食品海报图片大全 浏览:199
女生护腕图片 浏览:491
中国的美女风景图片大全 浏览:177
儿童房男生宿舍图片 浏览:874
word中图片表格显示编号 浏览:605
韩版中发烫发发型图片 浏览:42
文字图片壁纸路漫漫其修远兮 浏览:948
图片放进word怎么才能不变形 浏览:161