VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • excel vba教程之导出到文本文件 by:chenimbile

1.  导出到文本文件  by:chenimbile

http://www.excelpx.com/dispbbs.asp?boardid=5&id=13772&star=1#65435
Private Sub CommandButton1_Click()
Dim filesavename As String
Dim str2 As String
Dim x As Integer
Dim maxrow As Integer
filesavename = Application.GetSaveAsFilename( _
InitialFileName:="d:\", fileFilter:="Text Files (*.txt), *.txt")  ‘选择文件
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(filesavename, True)
maxrow = Range("e65535").End(xlUp).Row
For x = 4 To maxrow
    str2 = Range("e" & x).Value & "," & Range("f" & x).Value
    If x = maxrow Then
    a.write (str2)    ‘最后一行,系统自动加回车换行符,(Chr(13) + Chr(10))
    Else
     a.writeline (str2)
    End If
Next
a.Close
End Sub

相关教程