+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Macro for sheet importing working differently in 2007 vs 2003

    Need an extra set of eyes. I helped an OP in this thread:
    http://www.excelforum.com/excel-gene...le-import.html

    And he's getting no results, only getting a filename pasted into his activeworkbook. He's on Excel 2007 and I'm using 2003.

    Here's the macro and it works fine for me, importing all the files in one folder and pasting them one above the other in the activeworkbook:
    Code:
    Sub RunCodeOnAllXLSFiles()
    Dim lCount As Long, NR As Long
    Dim wbResults As Workbook, wbCodeBook As Object
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    On Error Resume Next
    
    Set wbCodeBook = ThisWorkbook.Sheets(1)
    NR = Range("A" & Rows.Count).End(xlUp).Row + 1
    
    With Application.FileSearch
        .NewSearch
         'Change path to suit
        .LookIn = "C:\My Computer\My Documents"
        .FileType = msoFileTypeExcelWorkbooks
        .Filename = "VT" & "*.xls"
    
            If .Execute > 0 Then 'Workbooks in folder
                For lCount = 1 To .FoundFiles.Count 'Loop through all.
                    'Open Workbook x and Set a Workbook variable to it
                    Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                    'Copy data
                    wbResults.Sheets(1).Range("A1").CurrentRegion.Copy
                    wbCodeBook.Range("A" & NR).PasteSpecial xlPasteAll
                    wbResults.Close SaveChanges:=False
                    NR = Range("A" & Rows.Count).End(xlUp).Row + 1
                 Next lCount
            End If
    End With
    
    On Error GoTo 0
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True
    End Sub
    I'm just looking for anything that might cause this to not work in his environment since I can't test it.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  2. #2
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,413

    Re: Macro for sheet importing working differently in 2007 vs 2003

    JBeaucaire,

    If you can get the Op to post a copy of a data file, I will test your code in Excel 2007.
    Last edited by stanleydgromjr; 05-30-2009 at 12:00 AM.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Macro for sheet importing working differently in 2007 vs 2003

    The OP said he could not, but the problem he's having is that it isn't reading the sheets anyway, it's just pasting in a sheet name. I actually saw that same thing once early on on setting up the macro, but it stopped doing that when I included the ws reference in the copy command.

    On my system, ALL the files I put in the designated directly get read into the activeworkbook and stacked one on top of the other.

    In fact, the VT* filter isn't actually working right, but that's ok since he said the folder would be only the files he wants read in anyway.

    If you could test it with just any scrap files, it should work indiscriminately. Thanks for checking it out.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  4. #4
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Macro for sheet importing working differently in 2007 vs 2003

    Application.FileSearch has been deprecated in XL2007.

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Macro for sheet importing working differently in 2007 vs 2003

    Quote Originally Posted by DonkeyOte View Post
    Application.FileSearch has been deprecated in XL2007.
    Ouch! Tough call...why take it out? Did they give 2007 users something better?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  6. #6
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Macro for sheet importing working differently in 2007 vs 2003

    I don't know the ins and outs as to why it was deprecated but if you google you will find lots and lots of disgruntled users and subsequent workarounds... there are no doubt some here too.

    The link below has a workaround c/o Nate Oliver (MS Excel MVP):

    http://www.mrexcel.com/forum/showthr...228168#1253882

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0