我在Word文档中有一堆图像,我使用以下脚本来调整大小。我有办法在每张图片后插入一个回车符吗?理想情况下,每个图像后需要双倍间距。我正在使用下面的脚本来调整图像大小。
Sub ResizePhotos()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
With pic
.LockAspectRatio = msoFalse
.Height = InchesToPoints(3.33)
.Width = InchesToPoints(4.44)
End With
Next
End Sub
答案 0 :(得分:0)
一个糟糕的解决方案,但我想我还是会发布它:
我在文档中添加了一个按钮,我想对其执行操作。然后我将以下宏指定给按钮:
Private Sub CommandButton1_Click()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
pic.Select
Selection.EscapeKey
SendKeys "{down}"
Selection.Text = Chr(13)
Next
End Sub
这将选择每个图像,以逃避选择。使用按键移动到下一行(但是,我确定可以通过编程方式完成此操作')然后插入回车符。
请将此作为一个想法,我确定上述方法可以在很多方面打破。
答案 1 :(得分:0)
请注意以下内容,而不是在图像后添加一个或多个回车符:
在文档中定义一种样式,类似于通常用于标题的样式(请参见下图),该样式具有您InlineShapes
或其段落所需的属性。例如
将您的样式保存为yourStyleFormat
以类似的方式调整您的代码
Dim pic As Word.InlineShape
For Each pic In ActiveDocument.InlineShapes
With pic
.LockAspectRatio = msoFalse
.Height = InchesToPoints(3.33)
.Width = InchesToPoints(4.44)
.Select
Selection.Style = ActiveDocument.Styles("yourStyleFormat")
End With
Next
优点:
缺点:
Select
很难看。我使用它,因为我无法弄清楚如何将.Style
应用于InlineShape
。因此,我首先选择它作为段落。我确定有一种更优雅的方式来访问图像parent-paragraph。答案 2 :(得分:0)
InlineShape有一个Range对象,表示它在文档中的位置。使用此功能,我们可以通过以下方式改进Martin的答案:
Dim pic As Word.InlineShape
For Each pic In ActiveDocument.InlineShapes
With pic
.LockAspectRatio = msoFalse
.Height = InchesToPoints(3.33)
.Width = InchesToPoints(4.44)
.Range.Style = "Your Style Name"
End With
Next
或者,如果你真的需要添加额外的段落:
For Each pic In ActiveDocument.InlineShapes
With pic
.LockAspectRatio = msoFalse
.Height = InchesToPoints(3.33)
.Width = InchesToPoints(4.44)
.Range.InsertAfter Chr(13)
End With
Next
答案 3 :(得分:0)
希望这将有助于特别的人
Sub rezize_center_newline()
Dim i As Long
Dim shpIn As InlineShape, shp As Shape
With ActiveDocument
For i = 1 To .InlineShapes.Count
With .InlineShapes(i)
.Height = InchesToPoints(4)
.Width = InchesToPoints(5.32)
.Range.InsertAfter Chr(13)
End With
Next i
For Each shpIn In ActiveDocument.InlineShapes
shpIn.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next shpIn
For Each shp In ActiveDocument.Shapes
shp.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next shp
End With
End Sub
答案 4 :(得分:0)
我刚刚创建了这个宏,它运行得很好。我重复了多次内容,以便可以搜索并替换许多图像。希望它有用:
Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^g"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
End Sub