调用wps文档(Word) 全选所有表格 全选所有符合条件的文字(可以使用通配符)

动作开发 · 49 次浏览
涛涛涛 创建于 5小时53分钟前

调用wps文档(Word) 全选所有表格  全选所有符合条件的文字
https://getquicker.net/subprogram?id=304435f8-c892-41a9-fc5d-08ddc017ed62    子程序

一.js宏代码
 
function 全选文档表格1()
{
Application.ScreenUpdating=false
for(var a of ActiveDocument.Tables){
a.Range.Editors.Add(-6)
}
ActiveDocument.SelectAllEditableRanges(-6)
ActiveDocument.DeleteAllEditableRanges(-6)
Application.ScreenUpdating=true
}
 
//如:全选所有vba或Vba文字
function 全选文档文字2()
    Application.ScreenUpdating=false
    qx=(obj=>{var a = "[Vv]ba";var b = "";var ss=true;
while(ss){
ss=obj.Execute(a, 1, 0, 1, 1, 1, 1, wdFindStop, 1, b, wdReplaceNone);
obj.Parent.Editors.Add(-1);
obj.Parent.Collapse(0)
}});
   qx(ActiveDocument.Content.Find)
   ActiveDocument.SelectAllEditableRanges(-1)
   ActiveDocument.DeleteAllEditableRanges(-1)
   Application.ScreenUpdating=true
}
 
 
 
 
二.C#代码
 
1全选文档表格
using Word=Microsoft.Office.Interop.Word;
// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context)
{
    var winObj = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");//获取当前启动的word程序
    winObj.ScreenUpdating=false;
    // 获取当前活动文档
    Word.Document doc = winObj.ActiveDocument;
Word.Tables tables = doc.Tables;
foreach (Word.Table table in tables)
   {
table.Range.Editors.Add(-6);
}
doc.SelectAllEditableRanges(-6);
    doc.DeleteAllEditableRanges(-6);
    winObj.ScreenUpdating=true;
}
 
2.全选文档文字
using Word=Microsoft.Office.Interop.Word;
// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context)
{
 
    var filePath = context.GetVarValue("g2") as string;// 读取查找的变量值
    var winObj = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");//获取当前启动的word程序
winObj.ScreenUpdating=false;
    // 获取当前活动文档
    Word.Document doc = winObj.ActiveDocument;
 
    var range = doc.Content as Word.Range;//需要实例化一个Word.Range对象
 
    range.Find.Text = filePath;//查找文本
    range.Find.MatchWildcards = true;//通配符开启
    range.Find.Wrap = Word.WdFindWrap.wdFindStop;//到达搜索范围的开始或者结尾时,停止执行查找操作
    range.Find.Forward = false;//从结尾向上查找
     while (range.Find.Execute())
     {
         range.Editors.Add(-6);
     }
    doc.SelectAllEditableRanges(-6);
    doc.DeleteAllEditableRanges(-6);
    winObj.ScreenUpdating=true;
}

 

涛涛涛 最后更新于 2025/7/11

回复内容
饺子吖 2小时37分钟前
#1

vba代码版全选表格:

Sub 全选文档表格()

    Application.ScreenUpdating = False

    Dim table As Table

    

    For Each table In ActiveDocument.Tables

        table.Range.Editors.Add wdEditorEveryone

    Next table

    

    ActiveDocument.SelectAllEditableRanges wdEditorEveryone

    ActiveDocument.DeleteAllEditableRanges wdEditorEveryone

    

    Application.ScreenUpdating = True

End Sub

回复主贴