Is there something inherent in saving as tab delimited text that adds an extra space at the end of the text? My code below works as I want, but the file created as text invariably has an extra space at the end. I know the answer is something incredibly simply, but I'm stumped?!
When I select/copy the dynamic range, it only selects the rows with data, and those rows have no extraneous spaces...
Can anyone help?
When I select/copy the dynamic range, it only selects the rows with data, and those rows have no extraneous spaces...
Can anyone help?
Code:
Sub CopyPasteTxt()
Dim Sht As Worksheet
' Unprotect Tool File
For Each Sht In ThisWorkbook.Worksheets
Sht.Unprotect Password:="password"
Next
' Dynamically select scan data from Tool File
Sheets("Scans").Select
Range("GarageInfo").End(xlDown).Select
' Copy dynamic range
Range("GarageInfo").Copy
' Paste into dummy workbook for text file save
Workbooks.Add
Worksheets("Sheet1").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues
' Save file name and path into a variable
template_file = ActiveWorkbook.FullName
gName = Range("A1").Value
sName = Range("A2").Value
' Default directory would be c:\temp. Users however will have the ability to change where to save the file if need be.
' Notice that i'm only allowing the save as option to be of .txt format.
fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:="C:\temp\" & gName & "_" & sName & ".txt", _
filefilter:="Text Files (*.txt), *.txt")
If fileSaveName = False Then
Exit Sub
End If
' Save file as .txt TAB delimited
ActiveWorkbook.SaveAs Filename:= _
fileSaveName, FileFormat:=xlText, _
CreateBackup:=False
file_name_saved = ActiveWorkbook.FullName
MsgBox "Your inventory upload file has been successfully created at: " & vbCr & vbCr & file_name_saved
' Protect Tool File
For Each Sht In ThisWorkbook.Worksheets
Sht.Protect Password:="password"
Next
'Email the upload file to the Control Room
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "joe@blow.com"
.CC = "john@doe.com"
.BCC = "jane@smith.com"
.Subject = "Upload file from " & gName & "_" & sName
.Body = "Upload file attached"
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
ActiveWorkbook.Close True
' closes the active workbook and saves any changes
End Sub