+ Reply to Thread
Results 1 to 8 of 8

Unable to programatically open a user selected file.

  1. #1
    Registered User
    Join Date
    10-15-2014
    Location
    Tennessee
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Question Unable to programatically open a user selected file.

    Hello.

    I'm programming a data comparison macro that looks at two spreadsheets and will highlight any differences between them. I'm having an early code problem:

    Please Login or Register  to view this content.
    The error is:
    Run-time error '91':
    Object variable or With block variable not set

    It happens at this specific line of code:

    Please Login or Register  to view this content.
    What am I missing, please?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Unable to programatically open a user selected file.

    You are missing "Set", no quotes at the beginning of the line of code.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Unable to programatically open a user selected file.

    Application.GetOpenFileName gets the filename it doesn't open the workbook.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Unable to programatically open a user selected file.

    This is the problem I believe:
    Please Login or Register  to view this content.

    You'll also have to adjust this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    10-15-2014
    Location
    Tennessee
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Thumbs up Re: Unable to programatically open a user selected file.

    Hot Damn!!!

    I learned from each of your posts, thank you so much!

    Modified code that works and successfully opens the file:

    Please Login or Register  to view this content.
    Last edited by LittleB; 10-16-2014 at 01:14 PM. Reason: Fixing code per Norie's forsight

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Unable to programatically open a user selected file.

    You're welcome. Thanks for the rep.


    We obviously all focused on a slightly different aspect

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

    Re: Unable to programatically open a user selected file.

    LittleB

    That code will fail if the user presses Cancel on the open file dialog.

    When they do that ComparisonFileName will be 'False', not Empty.

  8. #8
    Registered User
    Join Date
    10-15-2014
    Location
    Tennessee
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Re: Unable to programatically open a user selected file.

    Thanks for the follow-up Norie.

    You're right...I am modifying the code to fix it.

    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. Unable to open file
    By sudharshan86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2014, 06:22 AM
  2. Change password to open excel file programatically
    By stuht in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2013, 09:51 AM
  3. [SOLVED] Import worksheet from user selected file into open workbook
    By AWM1966 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-14-2012, 04:30 PM
  4. Unable to open file
    By yoyo2010 in forum Excel General
    Replies: 4
    Last Post: 01-21-2010, 07:49 AM
  5. [SOLVED] Unable to open excel file and when view the file size show as 1 KB
    By Kamal Siva in forum Excel General
    Replies: 1
    Last Post: 03-06-2006, 11:25 PM

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