+ Reply to Thread
Results 1 to 9 of 9

Extract data from open workbook, varying name.

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Extract data from open workbook, varying name.

    Good morning, Gurus.

    I run a daily report in which I download data from another source into an excel file, then manipulate the data, (copy and paste), to match existing row headings in my main report. I have created a macro which does this beautifully, with one small problem. Since the name of the imported file changes slightly from day to day, just a number in the file, I have to edit my macro daily to reflect this new file name before running my macro.

    Here is the macro, with the part containing the workbook filename highlighted in red. This workbook will always be open when I run my macro, and if necessary, I can assure ONLY this workbook and my main workbook file, (that I copy to), will be the only 2 Excel files open. The name of the file I download always comes in as "ppweb[#].xls", with the # being a single digit number from 1 to 9.

    Please Login or Register  to view this content.
    Thanks in advance for any help you can offer.

    Jerry

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    All you need to do is ensure hat your import workbook is the open & is activated. Then run the macro. Thisworkbook refers to the workbook containing the code, so this will copy from whichever workbook is active to the workbook that holds the code


    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Active Workbook?

    Thanks, Roy. One question: If I open the other workbook, containing the data I want to copy, and then go back to the workbook I want to copy to, whcih contains the macro, then isn't the workbook I want to copy to both the "active" workbook and the "thisworkbook"?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Open the imported workbook, then run the macro from the Tools menu

    Tools >- macros >- macro

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Thanks.

    I got it. You can select and run any macro from any open workbook, and the workbook where the macro actually resides is referred to as "thisworkbook".

    Simple enough. Thanks.

  6. #6
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Error

    Sorry, Roy, but I screwed something up.

    As soon as I run the macro from the active workbook, (the imported one), I get the following error:

    Run-time error '438':
    Object doesn't support this property or method.

    If I select to debug, the first line is highlighted:

    Please Login or Register  to view this content.
    Any idea what the problem is?

    Also, is there a way to run it from my main, (copy to), workbook which contains the macro? That way I could put a button on my main, and just click it to run, rather than having to scroll through the "Tools" menu.

    Thanks in advance for all your help.

    Jerry

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to add the sheet name

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Will this work?

    How's it going, Roy? Man, you must live on this site. Seems like you're always the first to answer.

    I never got this macro working the way I wanted, but I had a better idea. How would I just tell the macro to use the value of a cell as the "copy from" open workbook, and start the macro from there? Then when I see the name of the inported workbook, I just type that name in the cell, and hit the button to run the macro, all from my main workbook.

    Sound like a good solution?

  9. #9
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Bump

    Greetings, All.

    Still looking for a solution to this one. Any ideas?

+ 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