Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
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
Posted

Well, you could always use the VBA debugger...Debugging VBA[^] might help.

But I think it might be this:
VB
            SortArray vParagraphText
...
Private Function SortArray1(ByRef TheArray As Variant)
Perhaps if the two names matched, it might work more as you expected?
 
Share this answer
 
solution in C#.net WORD ADDIN

first create the class

C#
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

C#
private void button1_Click(object sender, RibbonControlEventArgs e)
       {
           Class1 c = new Class1();
           c.paraAlign(Globals.ThisAddIn.Application.ActiveDocument.Content);
       }
 
Share this answer
 
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);

}
 
Share this answer
 
solution in C#.net WORD ADDIN

sort the paragraph content separate by ;

first create the class

public void SeriesContent()
{
Word.Range R;
R = Globals.ThisAddIn.Application.Selection.Range;
string[] ParaArr;
string Swrite;
string Pstr;
Pstr = R.Text;
Pstr = Pstr.Replace('\r', ' ');
ParaArr = Pstr.Split(';');
System.Array.Sort(ParaArr);
Swrite = string.Join(";", ParaArr);
Swrite = Swrite + "\r";
R.InsertAfter(Swrite);
}


then use button click event

private void button1_Click(object sender, RibbonControlEventArgs e)
{
Class1 c = new Class1();
c.SeriesContent();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900