|
下面那段为什么会红?
Sub test2()
Dim FN As String, N%, W#, H#, PW#, PH#
With ActiveDocument.PageSetup '以下设置纸型及页边距(A4,页边距2cm),并计算出图片应有的宽高
.Orientation = wdOrientLandscape
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = CentimetersToPoints(2)
.RightMargin = CentimetersToPoints(2)
.Gutter = CentimetersToPoints(0)
.PageWidth = CentimetersToPoints(29.7)
.PageHeight = CentimetersToPoints(21)
PW = (.PageWidth - .LeftMargin - .RightMargin) / 2
PH = .PageHeight - .TopMargin - .LeftMargin
End With
FN = Dir(ActiveDocument.Path & "\" & "*.jpg")
Do While FN <> ""
Selection.InlineShapes.AddPicture "ActiveDocument.Path & " \ " & FN"
FN = Dir
Loop
For N = 1 To ActiveDocument.InlineShapes.Count
With ActiveDocument.InlineShapes(N)
W = .Width
H = .Height
If W / H >= PW / PH Then
.Width = PW * 0.99 '理论上讲图片的宽度应该刚好占版心宽度的一半,两个一半刚好撑满整个宽度,实际运用时应将图片再缩小一小点,否则两张图片还是可能处于不同的页,两张图片中间留出一条小缝也更好一些。
' .Height = PH * W / PW '插入图片时默认是锁定纵横比的,调整宽或高即可,两个都调反而有误。
Else
.Height = PH * 0.99
' .Width = PW * H / PH
End If
End With
Next N
ThisDocument.Save
End Sub
|
|