-
Help again please
Thanks to everyone who has tried to help in the past but perhaps I need to make myself more clear.
I need a VBA macro to read a .rpt file and load it into EXCEL:
1. Let the user select the file at time of input.
2. Format the input file correctly so that each field goes in a separate cell not everything in one cell.
3. Would also like to sort the file after it is imported by a column determined by the user.
4. Print out the worksheet after it has been loaded and sorted.
5. Close the worksheet automatically after printing.
I know that is a lot but if someone could point me in the right direction I would be appreciative. I am really under the gun on this one.
Here is the code I have so far:
[VBA] Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
Sub ImportTextLines()
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim WholeLine As String
Dim FName As String
Application.ScreenUpdating = False
ColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
FName = "D:\test.txt"
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
Cells(RowNdx, ColNdx).Value = WholeLine
ColNdx = ColNdx + 1
Wend
Close #1
End Sub
[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules