我正在使用 VBA 代码来减小文档中的图像以适应可打印的页面宽度:
Dim myPageWidthWithoutMargins As Single
myPageWidthWithoutMargins = ActiveDocument.PageSetup.PageWidth - ActiveDocument.PageSetup.LeftMargin - ActiveDocument.PageSetup.RightMargin
Dim myShape As InlineShape
For Each myShape In ActiveDocument.InlineShapes
myShape.LockAspectRatio = msoTrue
If myShape.Width > myPageWidthWithoutMargins Then
myShape.Width = myPageWidthWithoutMargins
End If
Next
它不能作为另一个 sub 的一部分工作,但它确实作为一个单独的宏工作,我在 sub 的所有其他操作完成后手动启动。为什么以及如何解决这个问题?
================
它是将 HTML 文件转换为相应的 Word 文档的 big sub 的一部分。这是之前用于处理图像的代码:
Dim myImgStyle As Word.Style
Set myImgStyle = ActiveDocument.Styles.Add("CenteredImageStyle", wdStyleTypeParagraph)
With myImgStyle
.BaseStyle = ActiveDocument.Styles(cNormalStyleName)
.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
Dim myShape As InlineShape
For Each myShape In ActiveDocument.InlineShapes
If Not myShape.LinkFormat Is Nothing Then
myShape.LinkFormat.SavePictureWithDocument = True
myShape.LinkFormat.BreakLink
myShape.Range.Select
Dim myParaRange As Range
Set myParaRange = Selection.Paragraphs.First.Range
If Selection.Start = myParaRange.Start And Selection.End = myParaRange.End - 1 Then
Selection.Style = myImgStyle
End If
End If
Next