Hi Paul,

Your recommendation solved my problem. I removed the if statement I
had and replace this line:

Do While excelFile <> ""

with this


Thanks a lot for your help.

Nasim


On Jan 6, 6:38 am, Paul Schreiner <schreiner_p...@att.net> wrote:
> I don't see where you're setting the variable: excelFile
>
> in the Editor, set a breakpoint at the statement:
> Do While Excelfile <> ""
>
> and step through.
>
> and watch the Excelfile Variable
>
> does ever equal "Combined Manual Timesheets.xls"?
>
> I would use:
> If ucase(excelFile) <> ucase("Combined Manual Timesheets.xls") Then
> ...
> your code
> ...
> end if
>
> It's possible that the "combined Manual Timesheet.xls" file will
> show up in the list BEFORE all of the files are processed.
> having it Exit Do when it encounters it will cause the macro
> to finish before all files are processed.
>
> Paul
>
> ________________________________
> From: Nasim <nbeiz...@gmail.com>
> To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com>
> Sent: Wed, January 5, 2011 11:41:10 PM
> Subject: $$Excel-Macros$$ Copy files in folder except one file
>
> Hi,
>
> I need to combine several excel files into one file. I create this new
> file in the directory that user chooses (this folder contains the
> files I want to copy). It loops trough the files and works perfectly
> except that it copies the "combined Manual Timesheets.xls" file and
> pastes it to itself (so the info is duplicated!)
> I get the folder from user in a function I found from net.
> how can I exclude this combined file from being copied?
>
> Thanks for your help in advance.
>
> Here is part of my code:
>
> Fpath = BrowseFolder(Caption:="Select the folder .")
> excelFile = Dir(Fpath & "\*.xls")
>
> ' I create the "Combined Manual Timesheets.xls" here
>
> Do While excelFile <> ""
>
> ' Do While excelFile <> "Combined Manual Timesheets.xls" or
> ""        :This line did not work
>
> 'This IF does not work for some reason:
>     If excelFile = "Combined Manual Timesheets.xls" Then
>         Exit Do
>     End If
>
>     Workbooks.Open Filename:=Fpath & "\" & excelFile
>
>     ' copy rows
>     ActiveWorkbook.Sheets(1).Activate
> LastRow = ActiveWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
>     ActiveSheet.Rows("8:" & LastRow).EntireRow.Select
>     Selection.Copy
>
>     With Workbooks("Combined Manual Timesheets.xls")
>         .Sheets(1).Activate
>         LastRow = .Sheets(1).Cells(Rows.Count, "B").End(xlUp).Row
>     End With
>
>     With Workbooks("Combined Manual
> Timesheets.xls").Sheets(1).Range("A" & (LastRow + 1))
>         ' Paste:=8 will copy the columnwidth in Excel 2000 and higher
>         .PasteSpecial Paste:=8
>         .PasteSpecial xlPasteValues
>
>     End With
>     Application.CutCopyMode = False
>     ActiveWorkbook.Save
>     Workbooks(excelFile).Close
>
>     excelFile = Dir
> Loop
>
> Thanks,
>
> Nasim
>
> --
> ----------------------------------------------------------------------------------
>
> Some important links for excel users:
> 1. Follow us on TWITTER for tips tricks and links 
> :http://twitter.com/exceldailytip
> 2. Join our LinkedIN group @http://www.linkedin.com/groups?gid=1871310
> 3. Excel tutorials athttp://www.excel-macros.blogspot.com
> 4. Learn VBA Macros athttp://www.quickvba.blogspot.com
> 5. Excel Tips and Tricks athttp://exceldailytip.blogspot.com
>
> To post to this group, send email to excel-macros@googlegroups.com
>
> <><><><><><><><><><><><><><><><><><><><><><>
> Like our page on facebook , Just follow below 
> linkhttp://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&;...

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts

Reply via email to