+ Reply to Thread
Results 1 to 10 of 10

Can't open another Workbook with VBA Excel

  1. #1
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Can't open another Workbook with VBA Excel

    All,

    I'm trying to open and import x cells from another Workbook with help of a Macro (assign to a command button).
    However, I can't get it to work. I can't open the Workbook itself. I get an error 400.

    Below the code
    Please Login or Register  to view this content.
    As you can see, I am already "looking" for all the available files in a certain folder, and when 1 is chosen, the filepath and filename is being collected.
    And I want to open this same workbook/sheet to get a few cells their value. I can't get it to open the workbook. (and no I didn't code in which cells yet, as I want to see if I can get it to work first).

    Any help would be appreciated.

    Thank you

    -=CWever=-

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: Can't open another Workbook with VBA Excel

    What is the actual value of OtherWorkbook when the code fails?
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Can't open another Workbook with VBA Excel

    Quote Originally Posted by rorya View Post
    What is the actual value of OtherWorkbook when the code fails?
    The way it is setup now, the code can't fail. The user has to click through a windows dialog and choose their folder.
    However, I can add a fail safe.

    I know, the error line..
    is
    Workbooks.Open

    there is the problem. But I don't understand why.
    Last edited by CWever; 12-01-2020 at 07:53 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: Can't open another Workbook with VBA Excel

    You didn't answer my question.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Can't open another Workbook with VBA Excel

    FolderName does not reflect the dir you have chosen to list the files from.

    Therefore you are looking in the wrong place for your workbook to open.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Can't open another Workbook with VBA Excel

    Quote Originally Posted by rorya View Post
    You didn't answer my question.
    Ok, there is no value when the code fail.

  7. #7
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Can't open another Workbook with VBA Excel

    Quote Originally Posted by bakerman2 View Post
    FolderName does not reflect the dir you have chosen to list the files from.

    Therefore you are looking in the wrong place for your workbook to open.
    Ok, now i'm lost. If I ask to paste the value in a cell I do get the whole path and filename.
    Please Login or Register  to view this content.
    It can be you are correct. That it doesn't know where to look at. But I find it strange that I do get the correct file path.
    This path is a variable that can change. So I cannot make it 'fix".

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Can't open another Workbook with VBA Excel

    Try this instead.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Can't open another Workbook with VBA Excel

    Quote Originally Posted by bakerman2 View Post
    Try this instead.

    Please Login or Register  to view this content.
    Weird, this now works. Thank you.
    I tried it so many times didn't work. Then I must have done something wrong before.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Can't open another Workbook with VBA Excel

    You're welcome and thanks for rep+.

+ 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] Using Workbook.Open to open an excel file with a variable path
    By walt737 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2019, 01:01 PM
  2. [SOLVED] vba to open excel workbook if alrady open by other user show userform and exit sub
    By bluepomme in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-06-2018, 07:14 PM
  3. Replies: 18
    Last Post: 09-15-2017, 09:30 AM
  4. [SOLVED] Fast Excel open, Slow Workbook open
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-28-2016, 11:09 AM
  5. VBA causing workbook to open whenever I open excel.
    By JessicaK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2015, 03:55 AM
  6. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM
  7. Replies: 2
    Last Post: 03-08-2005, 06:06 AM

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