+ Reply to Thread
Results 1 to 5 of 5

Opening A 2nd Workbook to Retrieve Data From then Closing that Workbook

  1. #1
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Opening A 2nd Workbook to Retrieve Data From then Closing that Workbook

    I am trying to import data from another workbook which requires an indirect function so the workbook must be open. The data is transferred during the IF statement, so I want the other workbook to open before the if statement and the workbook to close after the IF statement, both inside of the For loop. Also, when opening the workbook I want it to automatically say yes to the 2 defaults of Update and Continue (however, I have Application.DisplayAlerts = False and that isn't working). And finally, I don't want to save changes when I close the workbook (I always get an error when trying to active/close the workbook Run-time error 424). Thanks for all the help guys!

    Please Login or Register  to view this content.

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

    Re: Opening A 2nd Workbook to Retrieve Data From then Closing that Workbook

    The reason for the error is because NewWorkbook is string, which I assume contains the path and filename to the the workbook you want to copy from, and therefore doesn't have any properties/methods.

    I tried kind of rewriting the code a bit but got lost as it's not clear exactly what you want to do.

    One thing you definitely should do is create a reference to the workbook you are opening, then it should be easy to get data from it and then close it.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Opening A 2nd Workbook to Retrieve Data From then Closing that Workbook

    Could you explain what you mean by reference to the workbook? I'm new to VBA still trying to learn. Also, what do I need to do differently so that is isn't just seeing my path and filename which are combined in one cell as a string?

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

    Re: Opening A 2nd Workbook to Retrieve Data From then Closing that Workbook

    The values in the cell will always be strings, but you could create a reference to the workbook the refer to with something like this.
    Please Login or Register  to view this content.
    After the above code has been executed then you can refer to the opened workbook using the variable wbNew.

  5. #5
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Opening A 2nd Workbook to Retrieve Data From then Closing that Workbook

    Everything worked (including closing the workbook) except for the beginning prompt when the workbook opened. It still made me click update, but I didn't have the continue prompt directly afterward. This is the last thing standing in my way!

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Import A specified Range From Closed Workbook (without opening and closing)
    By webboj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2013, 05:47 AM
  2. Opening, refreshing, saving, and closing a closed workbook
    By hootiebsc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2013, 05:22 PM
  3. [SOLVED] How to clear the value of one cell upon opening or closing the workbook.
    By JET2011 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-31-2013, 09:00 AM
  4. Combobox code runs while closing and opening of workbook
    By shreyasdate in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2012, 07:47 AM
  5. Opening and closing one workbook after another
    By Nancy123 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-21-2010, 08:37 AM
  6. Problem With Opening and Closing A Workbook In VBA Using a Range Name In The Active W
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-28-2009, 09:22 AM
  7. Opening/Closing a Workbook(s) in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 11-08-2007, 03:37 AM
  8. protecting workbook but keeping groups available for opening/closing
    By lundgrendaniel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-15-2005, 05:34 PM

Tags for this Thread

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