读书人

excel vba怎么以txt方式打开文本文件

发布时间: 2012-12-16 12:02:32 作者: rapoo

excel vba如何以txt方式打开文本文件
如题
[解决办法]
仅供参考

?"begin...";: _
Set fs = CreateObject("Scripting.FileSystemObject"): _
Set a = fs.CreateTextFile("c:\alltext.txt", True): _
for each page in ThisDocument.Pages: _
a.WriteLine("----页:"+page.name+"----"): _
for each shape in page.Shapes: _
a.WriteLine(shape.Text): _
next: _
next: _
a.Close: _
Set a=Nothing: _
Set fs=Nothing: _
?"end"

[解决办法]
楼上的代码是什么意思?
怎么都是一行的呢?
是VB语句的么?
[解决办法]
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\alltext.txt", True)
for each page in ThisDocument.Pages
a.WriteLine("----页:"+page.name+"----")
for each shape in page.Shapes
a.WriteLine(shape.Text)
next
next
a.Close
Set a=Nothing
Set fs=Nothing

楼主自己查下联机帮助FSO部分有详解。

[解决办法]
Workbooks.OpenText Filename:="D:\a.txt", Origin:=936, StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter _
:=False, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
Other:=False, FieldInfo:=Array(1, 2), TrailingMinusNumbers:=True

以txt方式打开d:\a.txt

读书人网 >VB

热点推荐