+ Reply to Thread
Results 1 to 26 of 26

Close file via cell reference

  1. #1
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Close file via cell reference

    Hi

    I have this in my macro which works fine..
    Please Login or Register  to view this content.
    does any one know something similar to close the file again?

    Right now i use this:

    Please Login or Register  to view this content.
    But i want it to close the file by the contains of Q20 (just like when it opens)


  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    Presumably in cell Q10 you have something like C:\Temp\Spreadsheet1.xlsm am I correct? And using Windows(Range("Q10").Value).Close False is failing?

  3. #3
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    yes with this: Windows(Range("Q20").Value).Close False i get a bug..
    in Q20 i have C:\Users\DKJUHMET\Desktop\test.xlsm

  4. #4
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    I found a solution In Q21 i just write test.xlsm and then i works
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    That works, or to be consistent (i.e. avoid errors that the name in Q10 and Q11 are different), you can either formulate Q11 to extract Test.xlsm out. Or in your code, do
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    Thanks

    do you know if i can use this:
    Workbooks.Open Range("Q20").Value, ReadOnly:=True, UpdateLinks:=True

    To open a specific sheet by cell value also ?
    Sheet name GRAF in cell Q22

  7. #7
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    To open a specific cell, I believe you'll need to do something like this.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    it works, but i dont what any names in the macro, only references, so can it be done without the "GRAF" ?

  9. #9
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    Yes, you can, but you will need to record your current inputs first as you will be changing your active workbook and sheets
    For example if in Q12 you have "GRAF", and Q13 you have "Q22" then

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    i cant get i to work :/

  11. #11
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    Hmm.. it worked on mine. Although, I did notice a few things
    1) There's a stray quotation mark on
    Please Login or Register  to view this content.
    Remove it.

    2) When I saw cell Q12 should read "GRAF", I actually intended for you to type in GRAF into cell Q12, without the quotation marks.
    3) As per point 2, but for Q13 (type in Q22 instead of "Q22")

  12. #12
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    I still cant figure it out.

    I have in Q20 : C:\Users\DKJUHMET\Desktop\Test.xlsm
    In Q24 : GRAF

    The Q20 works perfectly to open and close with:

    Please Login or Register  to view this content.

    But i cant figure out what to do to make it open Sheet GRAF in the file C:\Users\DKJUHMET\Desktop\Test.xlsm

    The file i currently work in is called: C:\Users\DKJUHMET\Desktop\Data.xlsm

  13. #13
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    Without the spreadsheet in question I can only guess what the issue is. Are you able to attach a sanitised version of the two spreadsheets (i.e. no confidential data)?

    Can you check that the sheet name GRAF is correct? That is, the sheet name in Test.xlsm is actually GRAF without any spaces at the start or end of the sheet name.

    If you're certain its correct. Try this code, it's basically a combination of the above - but just to ensure that the recording of inputs are done before the workbook Test.xlsm is opened.

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    i get quit confussed when you write Q10, Q12 and Q13, i dont have anything in those.. only in Q20 and Q22 ??

    And yes it is GRAF without spaces
    i really appreciate your help

  15. #15
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    I got i to work Thanks a lot for your time and help

    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    Ah, you managed to figure it out before I got the time to respond. That's great.

    Enjoy your new VBA tool.

  17. #17
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    I found another problem maybe yu know the answer?

    In this macro, how do i use this togehter with it?
    ReadOnly:=True, UpdateLinks:=True


    Please Login or Register  to view this content.

  18. #18
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    To do that, you can either do...

    Please Login or Register  to view this content.
    OR...

    Please Login or Register  to view this content.
    I find the second option clearer.

  19. #19
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    thanks that works perfect !!

    You seem pretty good at this

    can i make this macro with cell value also? so i have A1:K48 writen in a cell an not in the macro?
    Please Login or Register  to view this content.

    should maybe be together with this one:
    Please Login or Register  to view this content.
    Last edited by MetteGaga; 06-30-2015 at 03:35 AM.

  20. #20
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    Hej MetteGaga, glad to be of help.

    The answer to the first problem. Yes. Again, depending on which cell you want to input the cell references.
    So for example, if you type A1:K48 in cell Q1 then resulting code is...

    Please Login or Register  to view this content.
    As for the second question, I'm not entirely sure where in the code to be adjusted? Can you clarify?

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    if i write
    Please Login or Register  to view this content.
    then the macro take Q1 in the file that is open wich is the on in q20, wich will be empty.. because i have the cell value ind the file that is soposed to take data from q20..

    does it make any sense?



    il just show you the macro i have, (wich works perfect) i just want to be able to change as much as posible via cell value and not in the macro it self (i have some kolleages that dont know how to work with macros. But if it is in cells they know how to do..

    Please Login or Register  to view this content.

  22. #22
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    I think I know what you mean. Perhaps something like this? Similar to what I have done for strSheetName and strRangeAddress.


    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    OMG, it works just like i want it to thanks a lot !!

  24. #24
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    Hi again

    the macro works so fine but how do i make it close without saving?

    Windows(Right(str, Len(str) - InStrRev(str, "\", -1))).Close

  25. #25
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Close file via cell reference

    When you say, "without saving" did you mean without Excel asking you whether to save or not? Try this.

    Please Login or Register  to view this content.

  26. #26
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Close file via cell reference

    yes that is what i was talking about thanks

+ 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] VBA Prompt to close PDF so file can be overwrtitten or close automatically
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2014, 12:31 PM
  2. [SOLVED] macro to save file to specific folder with file name from cell reference
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 11:32 AM
  3. Replies: 13
    Last Post: 02-13-2013, 01:00 PM
  4. Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file
    By Langchop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 05:09 AM
  5. How to: Open file, format data, save file, close file and repeat.
    By thexeber in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2010, 12:56 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