Hi,
I made a shortcut to save my Sheet into text format..
how could I add 2 more things to the script below.
I tried this but it turns out that I didn't put them where they should be..
1 . replace all alt+enter with space
altEnter.Value = Replace(altEnter, vbLf, " ")
2. save only selected columns (visible cell)
SpecialCells(xlCellTypeVisible)
Thank you very much
I made a shortcut to save my Sheet into text format..
how could I add 2 more things to the script below.
I tried this but it turns out that I didn't put them where they should be..
1 . replace all alt+enter with space
altEnter.Value = Replace(altEnter, vbLf, " ")
2. save only selected columns (visible cell)
SpecialCells(xlCellTypeVisible)
Thank you very much
Code:
Sub saveTxtV3()
Dim fileName As Variant
Dim rng As Range
Dim DelimChar As String
Dim LastRow As Long
Dim LastColumn As Long
On Error Resume Next
Set rng = Application.InputBox("select", Type:=8)
On Error GoTo 0
If rng Is Nothing Then Exit Sub
fileName = Application.GetSaveAsFilename("C:\Folder\" & ActiveSheet.Name, "Text File (*.txt), *.txt")
If fileName = False Then Exit Sub
If Dir(fileName) <> "" Then
If MsgBox("File '" & fileName & "' already existe. Overwrite?", vbYesNo + vbExclamation) <> vbYes Then Exit Sub
Kill fileName
End If
Open fileName For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
lineText = IIf(j = 1, "", lineText & vbTab) & rng.Cells(i, j)
Next j
Print #1, lineText
Next i
Close #1
MsgBox "Done"
CreateObject("Shell.Application").Open (fileName)
End Sub