+ Reply to Thread
Results 1 to 12 of 12

What am i missing to close user opened workbook?

  1. #1
    Registered User
    Join Date
    11-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    48

    What am i missing to close user opened workbook?

    Please Login or Register  to view this content.
    That's my code. The user clicks a button, selects a CSV file to copy the data from, then it automatically pastes the data to the original document. That all works beautifully.

    I've tried about 15 different things to close the user selected file. I've tried

    FileName.Close
    Workbooks.Close (FileName)

    I've tried activating the FileName file and doing a close. Tried about 8 other things on the internet. No idea. Please be possible and easy. Oh and I think I know how to do the SaveChanges False command... But if someone can help me and just throw that in anyway I'd appreciate it.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: What am i missing to close user opened workbook?

    Hi,

    Try this code (not tested) :

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    11-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: What am i missing to close user opened workbook?

    By jove it worked...
    Didn't even think about setting it as a workbook... I'm just happy I'm slowly figuring this vba stuff out.. I wasn't too far off but thank you!

    Threat will be changed to solved and rep added

  4. #4
    Registered User
    Join Date
    11-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: What am i missing to close user opened workbook?

    Actually take that back.. It's not pasting the data now.. But that's something I can figure out. Thanks again!

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: What am i missing to close user opened workbook?

    maybe it's the other changes I made...
    You should avoid using ".Select" and ".Activate" as it slows down the code.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    20,449

    Re: What am i missing to close user opened workbook?

    Logically wrong.

    1)
    Please Login or Register  to view this content.
    What if FileName = False ?
    should be
    Please Login or Register  to view this content.
    2)
    Please Login or Register  to view this content.
    Workbook doesn't have Range object.

    Please Login or Register  to view this content.
    Last edited by jindon; 09-30-2013 at 11:29 PM.

  7. #7
    Registered User
    Join Date
    11-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: What am i missing to close user opened workbook?

    The thing with SheetNameHere is that the sheet name varies based on the name the user saves the csv values as. I may save it as RyanData while Joe might save it as readings.. Then the sheet name would be wrong for joe.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    20,449

    Re: What am i missing to close user opened workbook?

    If csv, change to
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: What am i missing to close user opened workbook?

    Doesn't work... Doesn't even copy the data using:

    Please Login or Register  to view this content.

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

    Re: What am i missing to close user opened workbook?

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    20,449

    Re: What am i missing to close user opened workbook?

    change to
    Please Login or Register  to view this content.
    Note:
    Don't use On Error Resume when it is not needed.

  12. #12
    Registered User
    Join Date
    11-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: What am i missing to close user opened workbook?

    The suggestion from Norie worked...

    And jindon, the On Error Resume was from an older code that worked before the Workbook would close. If someone tried to open the same workbook twice, it would give an error and crash the file. So that's why that was there. It was a work around that kept the files from crashing.

+ 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. Automatic close Help file (.chm) which was opened with Excel user form
    By leecs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2013, 06:02 AM
  2. How to close an excel workbook opened in IE?
    By TiN Man in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2007, 07:52 PM
  3. Replies: 0
    Last Post: 08-23-2005, 09:05 PM
  4. Replies: 0
    Last Post: 08-23-2005, 09:05 PM
  5. Replies: 0
    Last Post: 08-23-2005, 09:05 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