+ Reply to Thread
Results 1 to 3 of 3

Switching EXCEL windows using a cell reference

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2000
    Posts
    3

    Re: Switching EXCEL windows using a cell reference

    Quote Originally Posted by Kenneth Hobson View Post
    It is easy to do. If you post example csv files and what the import should look like in the Excel file in a zip file.
    I have no objection to posting my CSV files, but I fail to see why you need my files specifically.

    The CSV files and their final format is not the problem here. It is the macro control of switching windows (not sheets) within the workbook.

    Create 2 simple CSV files of any data, any number of rows and columns.
    Name them as such "SU-modelname-components" and "SU-modelname-layers". There will be 16 of these in my final spreadsheet.

    Create a spreadsheet with 3 sheets, named "Macros", "components" and "layers"

    Define on the Macro sheet 5 cells and range name them as follows;
    "SUfilepath" containing the path to your CSV files - ie: "D:/sufiles/"
    "SUmodelname" containing the name of your CSV files "SU-modelname".
    "SUfilename" concatenating the file path & model name i:e "D:/sufiles/su-modelname"
    "CSV1file" containing the cell ref to "SUfilename"&"components.csv". It should look like "D:/sufiles/SUmodelname-components.csv"
    "CSV2file" containing the cell ref to "SUfilename"&"layers.csv". It should look like "D:/sufiles/SUmodelname-layers.csv"

    Now create a macro that does the following, BUT has no filenames hardcoded within the macro. It MUST read those names above from the sheet, as the models will change almost every run, as will the CSV data contents, but the formats and file type (ie: "-components" or "-layers") remain constant.

    Import the "components" CSV file. ("CSV1file") This will open a new window named "SUmodelname-components.csv"
    Copy the CSV data to the "components" sheet.
    Close the Components CSV window. I had to switch to the sheet to close it, but "Windows().activate" won't read the name from a rangename.
    Repeat for the "layers" CSV file.

    Is there another way to close a window, or better yet a way to load a CSV file directly into a specified sheet??
    Last edited by JGB; 07-26-2011 at 10:04 AM. Reason: added to last line.
    ttfn (Win 7, Excel 2002)
    jgb

+ 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