+ Reply to Thread
Results 1 to 3 of 3

Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file

  1. #1
    Registered User
    Join Date
    01-31-2013
    Location
    Johannesburg
    MS-Off Ver
    Excel 2003/ 2010
    Posts
    4

    Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file

    Hi There

    I am hoping someone can help me with this.. I know it should not be too complicated but my VB knowledge is purely from trial and error and not understanding.

    What I want to do is the following (I want to run these steps as separate macros for simplicity and ease of faultfinding, and run them sequentially using 'Application.Run "nextmacroname" ' function):

    Macro 1. In the main workbook (That houses the macros), a filepath and filename for a second workbook is given in cell A1 of sheet "DATA", and this is a variable ("c:\datafolder\130131.csv", which is derived from a formula and set to text format). The macro must open this second workbook (CSV opens as a workbook), and give an error message if the file is not found/ does not exist.

    Macro 2. This macro must ensure that the second workbook (again, the workbook name based on the variable file name in cell A1 of main workbook) is active [being a csv file format, it has only 1 worksheet with same name as the workbook itself ("130131")... not sure if the worksheet would also need to be 'activated' in this case ], select the first 3 columns of data (columns A:C), copy these, and paste these into the first 3 columns of the "DATA" worksheet of the main workbook.

    Macro 3. Close the second workbook (again, as before, workbook name based on the variable file name in cell A1 of main workbook), and ensure that any warnings are ignored (ie. 'do you want to save' , 'format may have changed' etc etc)

    From here I would be able to manipulate the data that has just been 'imported'



    What I have so far is the following:

    Macro 1: Some coding that I found on the forum which seems to work perfectly for this step:

    Please Login or Register  to view this content.
    (dont actually know why this works when my sheet is named "DATA" but this just refers to 'Sheet1 when referring to cell A1)

    Macro 2 & 3

    I have no idea how to do these... any help would be greatly appreciated


    Regards
    Lang
    Last edited by Langchop; 01-31-2013 at 05:06 AM.

  2. #2
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file

    Hi,

    To add code tags simply put highligh all of your current code above, and click the little hash # symbol
    Or manully type
    ["CODE] at the start of your post

    and then ["/CODE] at the end of your post

    Make sure you remove the " from both parts
    Last edited by galvinpaddy; 01-31-2013 at 04:21 AM.

  3. #3
    Registered User
    Join Date
    01-31-2013
    Location
    Johannesburg
    MS-Off Ver
    Excel 2003/ 2010
    Posts
    4

    Re: Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file

    Thanks galvinpaddy... changed for clarity

+ 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