感觉你的问题出现在选取##中的内容上 假如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 好了,我调试通过,你赶紧去修改吧.
感谢xiaolinyouni,已经解决问题,是由于存在换行衔和回车符导致的,去掉就可以了 nic = Replace(nic, Chr(10), "") nic = Replace(nic, Chr(13), "")由于连续回复三次不让再回复了,现在才发上来,结帖!
nic = replace(CStr(docApp.Selection.Text),vbcrlf,"")
nic = replace(nic,chr(0),"")
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)而不是你要找的“#测试#”
'docApp.Selection.TypeParagraph 回车换行
'docApp.Selection.MoveLeft Unit:=wdCharacter, Count:=1 左移一个字符上面这些是注释的内容,不起作用的。
.Text = "#"
.Wrap = wdFindContinue
End With这的.text=“#测试#”多好。难道你##中间的内容是可变的?
发邮件也行,[email protected]
当然是可变的,在Word中搜索标记,替换成Excel中的表格
如果你有好的替换方法也行,告诉我,我换种方法
假如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
好了,我调试通过,你赶紧去修改吧.
nic = Replace(nic, Chr(13), "")由于连续回复三次不让再回复了,现在才发上来,结帖!