Home |
Search |
Today's Posts |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you for all your support, I appreciate it very much. I did a file
check and I can see the problem now, I need to go back and redo the save routine. I will be glad to go back to Visual Basic; The more I dwell into Excel (VBA) it seems there pops up 100 things I don't know about it. Again, thank you for your support. -- Larry E. Brueshaber "Tom Ogilvy" wrote: No. Where you say it errors would indicate the filename is bad. Line Input reads an entire line. delimiters are meaningless to it. -- Regards, Tom Ogilvy "Larry" wrote in message ... In merging the files, were they delimited. I am trying to figure out if that is the problem. I am enclosing an example of a file that I am using: "DI554K",2103,525,0,"..",5,1222,200637,0,999948,1, 0,2 "DI554K",2103,525,0,"..",5,1222,200637,0,999940,1, 0,2 "DI554K",2103,525,0,"..",5,1222,200637,0,999939,1, 0,2 "DI554K",2103,525,0,"..",5,1222,200637,0,870185,1, 0,2 "DI554K",2103,525,0,"..",5,1222,200637,0,999938,1, 0,2 "DI554K",2103,525,0,"..",5,1222,200637,0,832338,1, 0,2 "DI554K",2103,525,0,"..",5,1222,200637,0,1060,1,0, 2 -- Larry E. Brueshaber "Tom Ogilvy" wrote: Code is tested and runs without a hitch for me. xl2003 even if SrcName were empty, that line won't raise an error: Demo'd from the immediate window: ? dir("") < "" True Now if SrcName = "some non existent path" You will get a 52 error or similar. Nothing I can do about it if you have bad data in your listbox. -- Regards, Tom Oglvy "Larry" wrote in message ... Running the module it is debugging to the line "If Dir(SrcName) < "" Then" then it exits. and the only thing created is an empty file. -- Larry E. Brueshaber "Tom Ogilvy" wrote: Sub AppendFiles1() Dim SourceNum As Long Dim DestNum As Long Dim Temp As String Dim SrcName As String Dim lbox As MSForms.ListBox Dim i As Long ' If an error occurs, close the files and end the macro. On Error GoTo ErrHandler ' Open the destination text file. DestNum = FreeFile() Open "E:\AA_Text\AAA_DEST.TXT" For Append As DestNum Set lbox = Userform1.ListBox1 '<=== sample correction For i = 0 To lbox.ListCount - 1 SrcName = lbox.List(i) If Dir(SrcName) < "" Then ' Open the source text file. SourceNum = FreeFile() Open SrcName For Input As SourceNum ' Read each line of the source file and append it to the ' destination file. Do While Not EOF(SourceNum) Line Input #SourceNum, Temp Print #DestNum, Temp Loop CloseFile: ' Close the source file. Close #SourceNum End If ' Dir(srcName) < "" Next i Close #DestNum Exit Sub ErrHandler: MsgBox "Error # " & Err & ": " & Error(Err) & " " & SrcName Resume CloseFile End Sub -- Regards, Tom Ogilvy "Larry" wrote in message ... I understand the problem now. The problem is I am on a Userform instead of an active worksheet. Sorry about the mis-understanding. -- Larry E. Brueshaber "Tom Ogilvy" wrote: Here is an example from the immediate window demonstrating it working perfectly set lbox = Activesheet.Listbox1 ? lbox.name ListBox1 ? typename(lbox) ListBox There was an issue with two variables being reversed - but you haven't reached that line yet, so no bearing on the above. Anyway here is a tested revision. It of course assume you a have a listbox from the control toolbox toolbar on the activesheet when you run the macro and the listbox has a list of fully qualified text file names. Sub AppendFiles1() Dim SourceNum As Long Dim DestNum As Long Dim Temp As String Dim SrcName As String Dim lbox As MSForms.ListBox Dim i As Long ' If an error occurs, close the files and end the macro. On Error GoTo ErrHandler ' Open the destination text file. DestNum = FreeFile() Open "E:\AA_Text\AAA_DEST.TXT" For Append As DestNum Set lbox = ActiveSheet.ListBox1 For i = 0 To lbox.ListCount - 1 SrcName = lbox.List(i) If Dir(SrcName) < "" Then ' Open the source text file. SourceNum = FreeFile() Open SrcName For Input As SourceNum ' Read each line of the source file and append it to the ' destination file. Do While Not EOF(SourceNum) Line Input #SourceNum, Temp Print #DestNum, Temp Loop CloseFile: ' Close the source file. Close #SourceNum End If ' Dir(srcName) < "" Next i Close #DestNum Exit Sub ErrHandler: MsgBox "Error # " & Err & ": " & Error(Err) & " " & SrcName Resume CloseFile End Sub -- Regards, Tom Ogilvy "Larry" wrote in message ... Entering in the Code, when running the module the following error "Object doesn't support this property or method" appears in line "set lbox = activesheet.listbox1". Thank you for your continues support. -- Larry E. Brueshaber "Tom Ogilvy" wrote: Assumes the Listbox is from the control toolbox toolbar and is on the activesheet. Sub AppendFiles1() Dim SourceNum As Integer Dim DestNum As Integer Dim Temp As String Dim SrcName as String Dim lbox as MSForms.Listbox ' If an error occurs, close the files and end the macro. On Error GoTo ErrHandler ' Open the destination text file. DestNum = FreeFile() Open "C:\DEST.TXT" For Append As DestNum set lbox = ActiveSheet.Listbox1 for i = 0 to lbox.Listcount - 1 SrcName = lbox.List(i) if Dir(srcName) < "" then ' Open the source text file. SourceNum = FreeFile() Open srcName For Input As SourceNum ' Read each line of the source file and append it to the ' destination file. Do While Not EOF(SourceNum) Line Input #SourceNum, Temp Print #DestNum, Temp Loop CloseFile: ' Close the source file. Close #DestNum End if ' Dir(srcName) < "" Next i Close #SourceNum Exit Sub ErrHandler: MsgBox "Error # " & Err & ": " & Error(Err) & " " & srcName Resume CloseFile End Sub -- Regards, Tom Ogilvy "Larry" wrote in message ... the listbox has a list of fully qualified filenames for text files which I want to combine into one large file. -- Larry E. Brueshaber "Tom Ogilvy" wrote: You mean the listbox has a list of fully qualified filenames for |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
merging zip files! | Excel Discussion (Misc queries) | |||
merging two files | Excel Discussion (Misc queries) | |||
Merging files | Excel Programming | |||
Merging two different files | Excel Discussion (Misc queries) | |||
Merging Files | Excel Programming |