Free Download Program Vba Code To Export Data From Excel To Text File

Free Download Program Vba Code To Export Data From Excel To Text File Delimited By

After few hours of effort this is the solution which might prove useful for many. Myspace. The key is to use named range of the rows you require to copy. Private Sub btnExportClickDim rng As RangeDim Sourceworksheet As WorksheetDim DestFile As StringDim cel As Range'Destination Path to place the text file.Application.DefaultFilePath = 'path'DestFile = Application.DefaultFilePath & 'Test.txt'Open DestFile For Output As #1Set Sourceworksheet = ActiveWorkbook.ActiveSheet' select the data or rows you need to copy and make it named range.Set rng = ShAuReport.Range('DataAuReport')For Each cel In rng.CellsWrite #1, cel.Address & ' ' & cel.Value2Next celClose #1MsgBox 'txt file exported'End SubRegards,Mani. First add reference to 'Microsoft Scripting Runtime' to use 'FileSystemObject'(Tools - References - check the box for 'Microsoft Scripting Runtime' and click ok)Sub WriteToTextFileDim fs As New FileSystemObjectDim rng As RangeDim ws As WorksheetSet ws = ActiveSheetSet txtfile = fs.CreateTextFile(ThisWorkbook.Path & 'test.txt')Set rng = Union(ws.Range('B6:D6'), ws.Range('B7:D7'), ws.Range('B14:D14'), ws.Range('B21:D21'))For Each r In rng.AreasFor Each cel In rtxtfile.Write (cel.Value & ' ')Nexttxtfile.Write (vbNewLine)NextEnd SubSee linnk:'.

Comments are closed.