+ Reply to Thread
Results 1 to 18 of 18

vba does not find new workbook

  1. #1
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    vba does not find new workbook

    Hello,

    Please Login or Register  to view this content.
    My excel application contains two workbooks, the second one directly created before running the code above.
    If I set a breakpoint before the for-loop and then execute the code, everything works fine. By executing the code in an automated manner, vba does not execute the code inside the if-statement.

    Why vba does not find the second workbook, it surely exists.

    Thank you very much!

    Lloyd

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: vba does not find new workbook

    Have you saved the new workbook so it has a name?

    Why are you looping to find the new workbook?

    You could set a reference to it as soon as it's created.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    No I haven't saved the workbook. It is a temporary file received by a filedownload.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: vba does not find new workbook

    Lloyd

    I thought you created the workbook in the code?

    Even if you didn't can't you set a reference to it when it's loaded/downloaded?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: vba does not find new workbook

    Wrong thread.

  6. #6
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    I trigger the filedownload via vba:

    Please Login or Register  to view this content.
    I know that sendkeys is problematic. But as far as I see there is no other option to download the file.

    How to set a reference to filedownload?

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: vba does not find new workbook

    Is the file actually opened in Excel?

  8. #8
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    Yes it is.

    In the same excel instance in another workbook.

    application.workbook contains two items. Item 1 is the workbook containing the vba code, item 2 is the downloaded csv-file.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    If that's the case you can refer to the new workbook with Workbooks(2).

    By the way, there alternatives to SendKeys.

    Don't have any links to hand but why not try a search?

  10. #10
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    Hi Norie,

    I have searched through the code of "http://www.google.com/trends/explore#q=euro%20crisis,%20euro%20vs%20dollar". To download the csv-file in a manual manner you need click the gearwheel looking button in the upper right. This buttons link is concatenated by a java function. As far as I know it is not possible to build and trigger this link via vba!?

    Lloyd

  11. #11
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    Please Login or Register  to view this content.
    That does not help. VBA is still not able to find the new object, if there is no manual interruption (breakpoint).

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Did that code cause an error or create a reference to another sheet?

  13. #13
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    It causes an error: Subscript out of range

    By setting a breakpoint in line Set aWBook = Workbooks(2) as expected.

  14. #14
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    It causes an error: Subscript out of range
    By setting a breakpoint in line Set aWBook = Workbooks(2) vba behaves as expected.

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Perhaps it's a timing issue.

    Why not try adding a sleep/wait?

  16. #16
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    sleep/wait also delays the download itself!

  17. #17
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook

    I still hang on this problem.

    Does anybody has an idea what is wrong?

  18. #18
    Forum Contributor
    Join Date
    04-05-2011
    Location
    behind you!
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: vba does not find new workbook


+ 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