saving selection as text file

brian1

New Member
Joined
Jun 25, 2002
Messages
23
I can't figure out how to save a selection as a text file. I just want to save a highlighted section of a workbook as a text file to use in access. Any suggestions?
 
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
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Glad to help & thanks for the feedback
 
Upvote 0
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
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,223,975
Messages
6,175,749
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top