本帖最后由 nic3259 于 2011-04-18 10:52:16 编辑

解决方案 »

  1.   

    估计你的nic 中含有回车或chr(0)之类try:
    nic = replace(CStr(docApp.Selection.Text),vbcrlf,"")
    nic = replace(nic,chr(0),"")
      

  2.   

    你在selection移动的时候,内容发生了变化。
    docApp.Selection.Find.Execute                              找到第一个#
    'docApp.Selection.MoveRight Unit:=wdCharacter, Count:=1    右移动一个字符
    'docApp.Selection.TypeParagraph                            回车换行
    'docApp.Selection.MoveLeft Unit:=wdCharacter, Count:=1     左移一个字符
    docApp.Selection.EndKey Unit:=wdLine, Extend:=wdExtend     移到本行的结尾
    此时docapp.selection.text=char(13)而不是你要找的“#测试#”
      

  3.   

    'docApp.Selection.MoveRight Unit:=wdCharacter, Count:=1 右移动一个字符
    'docApp.Selection.TypeParagraph 回车换行
    'docApp.Selection.MoveLeft Unit:=wdCharacter, Count:=1 左移一个字符上面这些是注释的内容,不起作用的。
      

  4.   

    你为什么在With docApp.Selection.Find
    .Text = "#"
    .Wrap = wdFindContinue
    End With这的.text=“#测试#”多好。难道你##中间的内容是可变的?
      

  5.   


    发邮件也行,[email protected]
      

  6.   


    当然是可变的,在Word中搜索标记,替换成Excel中的表格
    如果你有好的替换方法也行,告诉我,我换种方法
      

  7.   

    感觉你的问题出现在选取##中的内容上
    假如word中的#都是成对出现的.
    我给你选取##的代码Sub this()
    '
    ' this Macro
    ' 宏在 2011-4-18 选取##中的内容
    '
    Dim myrange As Range
    Dim aStart, aEnd As Long
    aStart = aEnd = 0
    Set myrange = ActiveDocument.RangeDo While aEnd <> ActiveDocument.Range.End
    With myrange.Find
    .Text = "#"
    .Execute
    aStart = myrange.Start
    .Execute
    End With
    aEnd = myrange.End
    myrange.SetRange Start:=aStart, End:=aEnd
    '此时myrangge.text="#测试#"
    '将word中的内容用excel单元格内容替换掉(你自己写)
    myrange.SetRange Start:=aEnd, End:=ActiveDocument.Range.End
    Loop
    End Sub
    好了,我调试通过,你赶紧去修改吧.
      

  8.   

    感谢xiaolinyouni,已经解决问题,是由于存在换行衔和回车符导致的,去掉就可以了    nic = Replace(nic, Chr(10), "")
        nic = Replace(nic, Chr(13), "")由于连续回复三次不让再回复了,现在才发上来,结帖!