excel - 如何调整 Word 文档中的图像大小?
问题描述
在 Excel 中,打开 Word 文档,将图像粘贴到当前位置,然后调整其大小。
我尝试在InlineShapes.AddPicture
.
这是插入图像的代码。
Sub CreateWordDocWithPicture()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
DocDirectory = "C:\Documents\"
Set wdApp = CreateObject("Word.Application") 'Create an instance of word
Set wdDoc = wdApp.Documents.Open(DocDirectory & "Template.docx", ReadOnly:=True)
'Open word file
wdApp.Visible = True
wdApp.Selection.InlineShapes.AddPicture Filename:=DocDirectory & "Image.jpg", LinkToFile:=False, SaveWithDocument:=True
End Sub
解决方案
例如:
Sub CreateWordDocWithPicture()
Dim wdApp As New Word.Application, wdDoc As Word.Document, wdIshp As Word.InlineShape
Const DocDirectory As String = "C:\Documents\"
With wdApp
.Visible = True
'Open word file
Set wdDoc = .Documents.Open(DocDirectory & "Template.docx", ReadOnly:=True)
With wdDoc
'Insert the image
Set wdIshp = .InlineShapes.AddPicture(FileName:=DocDirectory & "Image.jpg", _
LinkToFile:=False, SaveWithDocument:=True, Range:=.Range.Characters.Last)
'Resize the image
With wdIshp
.LockAspectRatio = True
.Height = InchesToPoints(1.5)
End With
End With
End With
End Sub
推荐阅读
- c# - MVC Razor 无法在 @foreach 循环内正确呈现 HTML
- ffmpeg - ffmpeg 在我尝试从一组帧创建视频时输出单帧视频
- python - 无法正确更改列表中的项目
- java - 在重复日期运行 java 函数
- django - 参考字段在 mongoengine 中存储什么
- javascript - 我可以使用 Javascript 将字符串转换为在 HTML 中浮动并获得平方根吗?
- powershell - Powershell 管道运算符与括号
- java - 如何使用 resttemplate 进行 WebDav 调用?
- amazon-s3 - 将 ELB 访问日志收集到 Cloudwatch 的最佳方法
- javascript - 如何在 jQuery 中提醒价格范围滑块值?