+ Reply to Thread
Results 1 to 11 of 11

Cycling through files in a folder

Hybrid View

KateMolloy Cycling through files in a... 09-21-2009, 07:28 AM
sweep Re: Cycling through files in... 09-21-2009, 07:38 AM
KateMolloy Re: Cycling through files in... 09-21-2009, 08:33 AM
sweep Re: Cycling through files in... 09-21-2009, 09:08 AM
KateMolloy Re: Cycling through files in... 09-25-2009, 06:07 AM
sweep Re: Cycling through files in... 09-25-2009, 06:34 AM
KateMolloy Re: Cycling through files in... 09-25-2009, 11:38 AM
jaslake Re: Cycling through files in... 09-25-2009, 09:24 PM
broro183 Re: Cycling through files in... 09-26-2009, 06:47 PM
KateMolloy Re: Cycling through files in... 09-28-2009, 08:49 AM
broro183 Re: Cycling through files in... 09-28-2009, 04:18 PM
  1. #1
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Cycling through files in a folder

    There's a couple of places that you have variables in quotes, which will result in the code not working.

    There's a ready made macro here which you may find useful
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  2. #2
    Registered User
    Join Date
    09-21-2009
    Location
    Nottingham, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Cycling through files in a folder

    Hi again,

    Thanks for the link, Dave, I've used the Macro you suggested and this has solved the problem I was having before. Unfortunately I've come across a new problem!

    I'm trying to do a basic copy and paste from one workbook to another. At the moment I have the sheets worked out (I think) but there's a problem with the pasting. The code I have in place at the moment (with a bit of extra around the edges) is:

     Do While strExtension <> ""
                Set wbOpen = Workbooks.Open(strPath & strExtension)
                With wbOpen
                    .Sheets("Sheet3").Select
                    Range("A3:B3").Copy
                    .Close SaveChanges:=False
                End With
                With wbNew
                    Cells(1, 1).Select
                    ActiveCell.SpecialCells(xlLastCell).Offset(1, 1).Select
                    ActiveSheet.Paste
                End With
                strExtension = Dir
            Loop
    The problem is that Excel doesn't like the ActiveSheet.Paste command for some reason! I've done the copy and paste manually while recording a Macro, and this is what it came up with, but when it's run on its own I get the error 'Object doesn't support this property or method'.

    I've tried loads of other paste options, including Selection.Paste and changing the Cell line above to .paste instead of .select (but I don't think the cells command works with paste), and changing the cells command to a range command, but this throws up yet more problems.

    I've simplified the macro to the real basics: I select the cells in the other workbook, then select the book I want to paste into and have the macro:

    Cells(1, 1).Select
                    ActiveCell.SpecialCells(xlLastCell).Select
                    Selection.Paste
    And while this is basically exactly what's recorded when I do it manually and record, when I run it as a macro I get the same problems.

    I've tried other methods of selecting the cell I need to paste into, such as columncount etc, but have had no luck either.

    I can't believe I'm having this much trouble with such a simple thing, so any help would be really appreciated!

    Thanks again,

    Kate

  3. #3
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Cycling through files in a folder

    Try activating a worksheet in wbNew by replacing this:

    With wbNew
    Cells(1, 1).Select
    with this:

    With wbNew
    Sheets(1).activate
    Cells(1, 1).Select
    I've used sheet 1 for an example.

  4. #4
    Registered User
    Join Date
    09-21-2009
    Location
    Nottingham, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Cycling through files in a folder

    Hi again Dave,

    Unfortunately that's one of the things I've tried. In fact I've still got it in in the mini macro I'm using to tease the problem out, but it hasn't helped. Should have posted it in the code, really, sorry about that.

    Just to check the line I have works, it's:

    Workbooks("data.xls").Worksheets("Sheet1").Activate

    Kate

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Cycling through files in a folder

    This may help (or not); tryu replacing this code
    Selection.Paste
    with
    Selection.PasteSpecial
    Hope this helps.
    J
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1