Word宏:如何组合和更改不同的内容控制元素

时间:2015-11-25 07:11:23

标签: vba ms-word word-vba

我对Macros和VBA没有任何经验,请原谅我的问题。我目前正在创建一个单词模板(Word 2016),其中包含我自己的功能区中的各种按钮。我使用宏来运行这些按钮,例如插入特定的表格格式,标题格式,列表格式等。我还想创建这样一个按钮,以特定的方式插入grafics。因此,我需要一个包含特定大小图片内容控制元素的表格,在表格下方我需要一个标题。问题:我无法更改内容控件元素的大小,并且未显示标题。如果我从我的计算机插入一个特定的图片它可以工作,但它不适用于其他电脑,这是必不可少的。有没有人有想法? 顺便说一句,这是我的代码:

Sub BildContent()
'
' BildContent Makro
'
'
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _

        1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed
    With Selection.Tables(1)
        If .Style <> "Tabellenraster" Then
            .Style = "Tabellenraster"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With
    Selection.Shading.Texture = wdTextureNone
    Selection.Shading.ForegroundPatternColor = wdColorAutomatic
    Selection.Shading.BackgroundPatternColor = 15523274
    Selection.Tables(1).Rows.LeftIndent = CentimetersToPoints(-4.5)
    Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints
    Selection.Tables(1).PreferredWidth = CentimetersToPoints(16.36)
    Selection.Style = ActiveDocument.Styles("Hinweistext Marginale")
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.Range.ContentControls.Add (wdContentControlPicture)
    Selection.InsertCaption Label:="Abbildung", TitleAutoText:= _
        "EinfügenBeschriftung1", Title:="", Position:=wdCaptionPositionBelow, _
        ExcludeLabel:=0
End Sub

0 个答案:

没有答案