它没有显示输出,这个VBA程序的任何一个帮助 [英] its not show the output , any one help for this VBA program
本文介绍了它没有显示输出,这个VBA程序的任何一个帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sub orderParagraph1()
Dim oParagraph As Word.Paragraph
Dim vParagraphText 正如 变体
对于 每个 oParagraph 在 ActiveDocument.Paragraphs
If Len(Trim(oParagraph.Range.text))> 0 然后
vParagraphText = oParagraph.Range.text
vParagraphText = split(vParagraphText, )
SortArray vParagraphText
结束 如果
下一步 oParagraph
结束 Sub
私有 功能 SortArray1( ByRef TheArray As Variant )
Dim x As 整数
Dim bSorted 作为 布尔
Dim sTempText 作为 字符串
bSorted = 错误
执行 不 bSorted
bSorted = True
对于 x = 0 UBound(TheArray) - 1
如果 TheArray(x)> TheArray(x + 1 )然后
sTempText = TheArray(x + < span class =code-digit> 1 )
TheArray(x + 1 )= TheArray(x)
TheArray( x)= sTempText
bSorted = False
结束 如果
下一步 x
循环
结束 功能
解决方案
好吧,你总是可以使用VBA调试器... 调试VBA [ ^ ]可能有帮助。
但是我墨水可能是这样的:
SortArray vParagraphText
...
私人 功能 SortArray1( ByRef TheArray As Variant )也许如果这两个名字匹配,它可能会按预期工作更多?
C#中的解决方案.net WORD ADDIN
首先创建班级
public void paraAlign(Word.Range range)
{
Word.Range T = range 。重复;
Word.Range R;
string StrP;
string [] Arr;
string Swrite;
int PCount;
PCount = Globals.ThisAddIn.Application.ActiveDocument.Paragraphs.Count;
int tempj = 0 ;
for ( int i = 1 ; i < = PCount; i ++)
{
R = Globals.ThisAddIn.Application.ActiveDocument.Paragraphs [i + tempj] 。范围;
StrP = R.Text;
StrP = StrP.Replace(' \ r',' ');
Arr = StrP.Split(' ');
System.Array.Sort(Arr);
Swrite = string .Join( ,Arr);
Swrite = Swrite + \ rr;
R.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
R.InsertAfter(Swrite);
tempj ++;
}
}
then使用按钮点击事件
private void button1_Click( object sender,RibbonControlEventArgs e)
{
Class1 c = new Class1();
c.paraAlign(Globals.ThisAddIn.Application.ActiveDocument.Content);
}
C#.net中的解决方案WORD ADDIN
商店新文件中的内容和数量
首先创建班级
public void OccuranceAllWordOther (Word.Range range)
{
//创建一个dic
字典< string,> WordDictionary = new Dictionary< string,>();
int _intW = 0;
string txt;
Word.Range T = range .Duplicate;
T.Collapse(Word.WdCollapseDirection.wdCollapseStart);
foreach(Word.Range RWord in range.Words)
{
RWord.Select();
txt = RWord.Text;
T.Find.Text = txt;
T.Find.MatchWholeWord = true;
T.Find.MatchCase = false;
_intW = 1;
txt = txt。修剪();
txt =+ txt;
if(WordDictionary.ContainsKey(txt)!= true)
{
if((!txt.Contains(())&&(!txt.Contains())))
{
Regex reg =新的正则表达式(txt) ;
MatchCollection match = reg.Matches(range.Text);
_intW = match.Count;
WordDictionary.Add(txt,_intW );
}
}
}
//创建一个文本文件并粘贴值
CreateTextFile(WordDictionary,@C:\ Users \201875 \Desktop\out.txt);
}
然后使用按钮点击事件
public void CreateTextFile(Dictionary< string,> SampleWord,string pathname)
{
string outputText = null;
if(File.Exists(pathname))
{
File.Delete(路径名);
}
使用(StreamWriter Sw = File.CreateText(pathname))
{
foreach(KeyValuePair< string,> SampleWord中的Dicmain)
{
outputText = Dicmain.Key + :+ Dicmain.Value;
Sw.WriteLine(outputText);
}
}
} < br $>
private void button1_Click(object sender,RibbonControlEventArgs e)
{
Class1 c = new Class1();
c.OccuranceAllWordOther(Globals.ThisAddIn.Application.ActiveDocument.Content);
}
Sub orderParagraph1() Dim oParagraph As Word.Paragraph Dim vParagraphText As Variant For Each oParagraph In ActiveDocument.Paragraphs If Len(Trim(oParagraph.Range.text)) > 0 Then vParagraphText = oParagraph.Range.text vParagraphText = split(vParagraphText, " ") SortArray vParagraphText End If Next oParagraph End Sub Private Function SortArray1(ByRef TheArray As Variant) Dim x As Integer Dim bSorted As Boolean Dim sTempText As String bSorted = False Do While Not bSorted bSorted = True For x = 0 To UBound(TheArray) - 1 If TheArray(x) > TheArray(x + 1) Then sTempText = TheArray(x + 1) TheArray(x + 1) = TheArray(x) TheArray(x) = sTempText bSorted = False End If Next x Loop End Function解决方案Well, you could always use the VBA debugger...Debugging VBA[^] might help.
But I think it might be this:
SortArray vParagraphText ... Private Function SortArray1(ByRef TheArray As Variant)Perhaps if the two names matched, it might work more as you expected?
solution in C#.net WORD ADDIN
first create the class
public void paraAlign(Word.Range range) { Word.Range T = range.Duplicate; Word.Range R; string StrP; string[] Arr; string Swrite; int PCount; PCount =Globals.ThisAddIn.Application.ActiveDocument.Paragraphs.Count; int tempj = 0; for (int i = 1; i <= PCount; i++) { R = Globals.ThisAddIn.Application.ActiveDocument.Paragraphs[i + tempj].Range; StrP = R.Text; StrP = StrP.Replace('\r', ' '); Arr = StrP.Split(' '); System.Array.Sort(Arr); Swrite = string.Join(" ", Arr); Swrite = Swrite + "\r"; R.Collapse(Word.WdCollapseDirection.wdCollapseEnd); R.InsertAfter(Swrite); tempj++; } }
then use button click event
private void button1_Click(object sender, RibbonControlEventArgs e) { Class1 c = new Class1(); c.paraAlign(Globals.ThisAddIn.Application.ActiveDocument.Content); }
solution in C#.net WORD ADDIN
store the content and count in new file
first create the class
public void OccuranceAllWordOther(Word.Range range)
{
//Create a dic
Dictionary<string,> WordDictionary = new Dictionary<string,>();
int _intW = 0;
string txt;
Word.Range T = range.Duplicate;
T.Collapse(Word.WdCollapseDirection.wdCollapseStart);
foreach (Word.Range RWord in range.Words)
{
RWord.Select();
txt = RWord.Text;
T.Find.Text = txt;
T.Find.MatchWholeWord = true;
T.Find.MatchCase = false;
_intW = 1;
txt = txt.Trim();
txt = " " + txt;
if (WordDictionary.ContainsKey(txt) != true)
{
if ((!txt.Contains("(")) && (!txt.Contains(")")))
{
Regex reg = new Regex(txt);
MatchCollection match = reg.Matches(range.Text);
_intW = match.Count;
WordDictionary.Add(txt, _intW);
}
}
}
// create a text file and paste the values
CreateTextFile(WordDictionary, @"C:\Users\201875\Desktop\out.txt");
}
then use button click event
public void CreateTextFile(Dictionary<string,> SampleWord, string pathname)
{
string outputText = null;
if (File.Exists(pathname))
{
File.Delete(pathname);
}
using (StreamWriter Sw = File.CreateText(pathname))
{
foreach (KeyValuePair<string,> Dicmain in SampleWord)
{
outputText = Dicmain.Key + ":" + Dicmain.Value;
Sw.WriteLine(outputText);
}
}
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Class1 c = new Class1();
c.OccuranceAllWordOther(Globals.ThisAddIn.Application.ActiveDocument.Content);
}
这篇关于它没有显示输出,这个VBA程序的任何一个帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文