繁体   English   中英

尝试在 Word 2016 中添加 Buildingblock 时出现“无效参数”

[英]"Invalid paramenters" when trying to add Buildingblock in Word 2016

当我尝试在 Word 2016 中添加构建块时,我得到无效参数。

范围是表格中的一个单元格(最后一行的第一个单元格)。 Activedocument 是我想添加构建块的模板。

private void CreateNewBuildingblock(string sBuildingblockName)
{
  Document currentDocument = Globals.ThisAddIn.Application.ActiveDocument;
  Template templateFile = (Template) currentDocument.get_AttachedTemplate();
  currentDocument.Tables[1]
    .Cell(currentDocument.Tables[1].Rows.Count, 1)
    .Range.Text.Substring(
      0,
      currentDocument.Tables[1]
        .Cell(currentDocument.Tables[1].Rows.Count, 1)
        .Range.Text.Length - 2
    );

  Range rBuildingblockContent = Globals.ThisAddIn.Application.Selection.Range;
  _ = templateFile.BuildingBlockEntries.Add(
    Name: sBuildingblockName,
    Type: WdBuildingBlockTypes.wdTypeCustom1,
    Category: "Generals",
    Range: rBuildingblockContent,
    Description: "AV_Buildingblock",
    InsertOptions: WdDocPartInsertOptions.wdInsertParagraph
  );
}

任何建议/帮助表示赞赏!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM