我头都大了。。希望大家帮忙。
需求很简单,就是一个word的doc里每一行有一个单词。文件很大。。可能有几百几千行
比如:
this
when
that
.....
我想用VBA来获取每一行的单词,然后输出到一个文件里。我自己试着写了下,就是不对。。不知道是不是函数选错了。。是不是我对ActiveDocument.Words(hs).Text;理解有错误?Sub Macro1()
On Error Resume Next
Open "c:\a.csd" For Output As #1
For hs = 1 To ActiveDocument.BuiltInDocumentProperties("Number of lines").ValuePrint #1, ActiveDocument.Words(hs).Text;Next
Close #1
End Sub
当我这个文件有几百行的时候,总是不能全部输出,困扰我很久了,求大家帮忙。。
需求很简单,就是一个word的doc里每一行有一个单词。文件很大。。可能有几百几千行
比如:
this
when
that
.....
我想用VBA来获取每一行的单词,然后输出到一个文件里。我自己试着写了下,就是不对。。不知道是不是函数选错了。。是不是我对ActiveDocument.Words(hs).Text;理解有错误?Sub Macro1()
On Error Resume Next
Open "c:\a.csd" For Output As #1
For hs = 1 To ActiveDocument.BuiltInDocumentProperties("Number of lines").ValuePrint #1, ActiveDocument.Words(hs).Text;Next
Close #1
End Sub
当我这个文件有几百行的时候,总是不能全部输出,困扰我很久了,求大家帮忙。。
就几行也不能全部输出。。
譬如我的doc里有这么几行单词:
achieve
that
they
thousands
together
variables
vary
view
when程序运行后,生成的a.csd里就这么几行:
achieve
that
they
thousands
together
剩下的几个词跑哪去了?
On Error Resume Next
Open "c:\a.csd" For Output As #1
Dim intNum As Integer
intNum = ActiveDocument.BuiltInDocumentProperties("NUMBER OF LINES").Value
For hs = 1 To intNum * 2Print #1, ActiveDocument.Words(hs).Text;Next
Close #1
End Sub