+ Reply to Thread
Results 1 to 3 of 3

Problem opening files within code

  1. #1
    Registered User
    Join Date
    10-05-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010, 2011
    Posts
    2

    Smile Problem opening files within code

    I am struggling to complete a project with a client; unfortunately he's in Japan whilst I'm in the UK, so we're working remotely.

    The code I've written asks for a folder to be selected; it then takes all .csv files that are within that folder, copies the data contained, carries out formatting and saves off each worksheet as a new workbook.

    Everything works fine on my computer (PC running Excel 2010).

    My client is having variable results. We've traced this to an issue in the "find .csv files" portion of the code.

    In an attempt to understand the issue, I modified the code being used to find / cycle through files in order to simply provide a list of files within the folder - in order that he could return this to me and I would at least be able to see what filenames / extensions were present in the folder.

    However, it now transpires that when he uses this trial code, regardless of which folder he selects in the "open folder" dialogue, the macro shows the contents of his Desktop folder.

    Anyone able to solve my headache and suggest what's going on?!

    Code used is as follows:

    Please Login or Register  to view this content.
    This is modded code from ExcelExperts.com - http://www.excelexperts.com/VBA-Tips...es-In-A-Folder.
    Last edited by Dom W; 10-05-2011 at 12:28 PM. Reason: Problem solved!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Problem opening files within code

    I am not sure why you are getting different behavior on the two systems, but I think it is flawed to assume that the current directory will be changed to the one selected by the dialog. CurDir will return the current directory, and in your client's case it is clearly the desktop, and it is not being changed.

    This code will explicitly take the folder selected in the dialog, replacing the original line that I show as commented out:
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 10-05-2011 at 11:58 AM. Reason: removed extraneous code not related to my changes
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-05-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010, 2011
    Posts
    2

    Re: Problem opening files within code

    Face. Palm.

    Obvious when you see it - thanks!

+ 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