saving selection as text file

jaystub

New Member
Joined
Nov 12, 2017
Messages
6
Fluff,
I am indebted to you for solving my excel problem. You truly have a mastered skill with this. The macro now works great. Thank you again for your assistance.

,jaystub
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
39,053
Office Version
365
Platform
Windows
Glad to help & thanks for the feedback
 

sajjadnb

New Member
Joined
Feb 25, 2018
Messages
1
Hi,

i tried the code and it works great. i have 0 knowledge of the VB code, however i was wondering how can we modify this code to save the selected range in a Pipe separated format instead of Tab, along with a save-as option.

Thanks and Regards,Sajjad Baig
 

Dossfm0q

Board Regular
Joined
Mar 9, 2009
Messages
212
Try this
Code:
[FONT=arial]Public Sub ToText()[/FONT]
[FONT=arial] Dim fso As Object[/FONT]
[FONT=arial] Set fso = CreateObject("Scripting.<wbr>FileSystemObject")[/FONT]
[FONT=arial] Dim Fileout As Object[/FONT]
[FONT=arial] Dim Ext As String 'Extension[/FONT]
[FONT=arial] On Error Resume Next[/FONT]
[FONT=arial] Path = CreateObject("WScript.Shell").<wbr>SpecialFolders("Desktop")[/FONT]
[FONT=arial] Ext = "txt" '   Ext="[/FONT][COLOR=#333333]cnc[/COLOR][FONT=arial]" or [/FONT][FONT=arial] Ext=[/FONT][FONT=arial] "[/FONT][COLOR=#333333]csv[/COLOR][FONT=arial]"[/FONT]
[FONT=arial] Set Fileout = fso.CreateTextFile(<wbr>ThisWorkbook.Path & "\vba.Ext", True, True)[/FONT]
[FONT=arial] Set Fileout = fso.CreateTextFile(Path & "\vba.txt", True, True)[/FONT]
[FONT=arial]  On Error GoTo 0
[/FONT]''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
[FONT=arial]  Set MyRange = Range("A3:H5") 'Select Your Range'
[/FONT]''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

[FONT=arial]         Fileout.Write "Good Day All" & vbNewLine[/FONT]
[FONT=arial]         Fileout.Write "What you want to say" & vbNewLine[/FONT]
[FONT=arial]        For Each Rng In MyRange[/FONT]
[FONT=arial]            Fileout.Write Rng.Value & vbNewLine[/FONT]
[FONT=arial]        Next[/FONT]
[FONT=arial]         Fileout.Write "end of message" & vbNewLine[/FONT]
[FONT=arial]         Fileout.Write "Thank" & vbNewLine[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    Fileout.Close[/FONT]
[FONT=arial]    Shell "Notepad " & ThisWorkbook.Path & "\vba.txt", vbMaximizedFocus[/FONT]
[FONT=arial]End Sub[/FONT]
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,096,306
Messages
5,449,572
Members
405,572
Latest member
Oberon

This Week's Hot Topics

Top