LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to export data to fixed width not saving right justifcation

Hello All,
I have a macro to export data to a fixed width text file. The macro runs
fine but when I open up the txt file I noticed that three fields that I had
right justified are left justified in the txt file.
This is my macro. There seems like there should be an easy way to keep the
justification but I have not been able to find it when searching. Any help
you can offer would be appreciated. Thanks for your time. Here is the macro
code:

Sub MakeFixedWidth()

Dim Sizes As Variant
Dim arr As Variant
Dim r As Long, c As Long
Dim fso As Object
Dim ts As Object
Dim TheLine As String
Dim TestStr As String

Sizes = Array(9, 20, 20, 1, 1, 30, 30, 20, 2, 9, 8, 8, 1, 5, 2, 10, 11, 1,
7, 7, 8)

arr = ActiveSheet.UsedRange

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("c:\filename.txt", True)

For r = 1 To UBound(arr, 1)
TheLine = ""
For c = 1 To UBound(arr, 2)
TestStr = Left(Trim(CStr(arr(r, c))), Sizes(c - 1))
TheLine = TheLine & TestStr & String(Sizes(c - 1) - Len(TestStr), " ")
Next c
ts.WriteLine TheLine
Next r

ts.Close

Set ts = Nothing
Set fso = Nothing

MsgBox "Done"

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed Column Width Export [email protected] Excel Discussion (Misc queries) 1 March 27th 08 01:27 PM
Macro to Export to a Fixed Width txt file Little Penny Excel Programming 5 September 8th 07 01:18 AM
How to export to fixed width text file? Mike Excel Worksheet Functions 1 October 17th 05 09:30 PM
Export to fixed width text file FinChase Excel Discussion (Misc queries) 0 January 24th 05 07:25 PM
Fixed Width - Opening Certain Fixed Width Files Jan[_8_] Excel Programming 2 December 30th 03 08:31 PM


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"