我是将一段VB代码转化为VC代码,意思是求word中选中的一段的行数。im LineCount As Integer //Lxx 声明变量
Sub LinesCount() //函数,计算行数
    Dim l As String 
    On Error Resume Next 
    '如果光标未选中内容则将第一个光标所在段落选中 
    If Selection.Type = wdSelectionIP Then Selection.Paragraphs(1).Range.Select 
    Application.ScreenUpdating = False    '关闭屏幕更新 
    CommandBars("Word Count").Visible = True    '打开字数统计工具栏 
    '执行字数统计(重新计数) 
    CommandBars("Word Count").Controls(2).Execute 
    '返回第一个列表框中的第六个数据 
    l = CommandBars("Word Count").Controls(1).List(6) 
    '关闭字数统计 
    CommandBars("Word Count").Visible = False 
    Application.ScreenUpdating = True    '恢复屏幕更新 
    LineCount = Int(Mid(l, 1, Len(l) - 1))    '返回行数值 
    '返回所选段落(或光标所在段落)的行数 
    MsgBox "Selection Paragraphs(1)'s Line Count Is " & LineCount 
    '返回指定行数的内容 
    MsgBox NumlineRange(LineNumber) 
End Sub 
vc代码是:
Cell cell = wd.m_wdTb.Cell(5,1);
Range rg = cell.GetRange();
Paragraphs ps = rg.GetParagraphs();
long count = ps.GetCount();
Paragraph ph;
long tCount = 0; 
for (int i = 1;i < count;i++)
{
ph = ps.Item(i);
Range rge = ph.GetRange();
rge.Select();
/////////////////求选中段落的行数///////////////////////////////////////////////
wd.m_wdApp.SetScreenUpdating(FALSE);
wd.wdCBar.AttachDispatch (wd.wdCBars.GetItem(COleVariant("Word Count")),TRUE);
wd.wdCBar.SetVisible(TRUE);
CommandBarControls cs = wd.wdCBar.GetControls();
long kc = cs.GetCount();//2
CommandBarControl c1 = cs.GetItem(COleVariant("2"));//出错!!!!!!!!!!!!!!!!!!!!
c1.Execute();
CommandBarControl c2 = cs.GetItem(COleVariant("1"));
CString css = c2.GetParameter();
wd.wdCBar.SetVisible(FALSE);
wd.m_wdApp.SetScreenUpdating(TRUE);
}