+ Reply to Thread
Results 1 to 21 of 21

Closing and re-opening the same file in excel

  1. #1
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119

    Closing and re-opening the same file in excel

    Hi All,

    I was wondering if there is any code using an on-click method. When clicking a button i need excel to exit the file/sheet without saving (no prompts) and then re-open the exact same file/sheet once it has closed.

    In a way this is like a refresh button.

    Advice or code to help me would be appreciated as VBA is not my strong point.

    Thanks
    Last edited by thompsy121; 10-19-2008 at 08:23 AM.

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi thompsy121,

    To close a work book you can use the following code
    Please Login or Register  to view this content.
    To ensure no prompts apear you can use this
    Please Login or Register  to view this content.
    and finally to open a workbook you can use this
    Please Login or Register  to view this content.

    so final code looks like this
    Please Login or Register  to view this content.
    Please note that when you turn display alerts off it will use the default value as the answer (in this case it is no, so the workbook will not save).
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

  3. #3
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Hi thanks for that,

    The form closes ok, but somehow it does not open back up. I have checked the file name path and that is fine????

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Once you have closed the workbook the macro will stop running, so it cannot re-open itself.

    Create a Template workbook instead

    http://www.excel-it.com/excel_templates.htm
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    thanks for that,

    Is there possibly another way where i can just close down the worksheet and then re-open it leaving Microsoft Excel open????


    Thanks

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The macro is in the workbook, when the workbook closes the macro stops running. You could possibly put the code into an addin or PERSONAL>xls

  7. #7
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    The reason i need this code is i have a workbook that links data from another workbook which is updated daily. The workbook i need the code on will be displayed on a central computer via a plasma screen.

    What i need is where workbook 1 is updated, i need workbook 2 to update while being on screen.

    Can this be done automatically? If not, is there some code i can use to refresh workbook 2 via an on-click method?

    Help on this would be really appreciated.

    Thanks

  8. #8
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    If you used links you cud make it refresh the links to show the updated data.

    or could you not have another workbook open that will close and re open the other workbook. if you turn off screenupdating while closing and opening you would hardly see it do anything but change the data on the sheet

    and sorry about my code earlier i wasnt thinking when i came up with it. lol
    Last edited by Stuie; 10-16-2008 at 09:35 AM.

  9. #9
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Do you know any good code i could use as an automatic refresh every X seconds, or an on-click refresh?

    Thanks

  10. #10
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    to get a time in Excel the only way that i could think of would be to use an infinate loop that checks the time and then when the time is in x number of seconds execute the code and then start all over.

    if not another way to open and close files every x seconds would be to write a .bat file i think would do it (im not 100% sure) i dont have much experiance with them

  11. #11
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Quote Originally Posted by Stuie View Post
    to get a time in Excel the only way that i could think of would be to use an infinate loop that checks the time and then when the time is in x number of seconds execute the code and then start all over.

    if not another way to open and close files every x seconds would be to write a .bat file i think would do it (im not 100% sure) i dont have much experiance with them

    Thanks for that Stuie, does any1 else know how to do this what Stuie suggested?

    Thanks

  12. #12
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    value of x

    Hi
    You can probably use scheduled tasks from control panel. It opens excel file at preset time. How frequently you want it refreshed? In otherwords what is the value of X
    Ravi
    Last edited by ravishankar; 10-18-2008 at 12:39 PM.

  13. #13
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Quote Originally Posted by ravishankar View Post
    Hi
    You can probably use scheduled tasks from control panel. It opens excel file at preset time. How frequently you want it refreshed? In otherwords what is the value of X
    Ravi
    I would need it refreshed every 5 seconds if possible.

  14. #14
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    if you are considering a picece of third pary software, i have experiance with VB.net and could put together a small app that will take the file name and file path, open it up and then close and re-open every 5 seconds this wouldnt be too difficult at all the only problem being i only have office 2007 and i dont have the class library for off 2003

  15. #15
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Thanks for the offer Stuie,

    But i've just looked over the last part of formula you suggested.

    so final code looks like this
    Please Login or Register  to view this content.

    I have only used the following part - Workbooks.Open "Place file name here" 'Opens a workbook
    Application.DisplayAlerts = True 'Turns alerts back on[/CODE]


    As this league workbook is a view only table, there is no need to save any updated figures. Ive tried it and i think it works. Do you think this is an ok way to do it.

    If the file is already open, this in a way forces a close and then re-opens.

    Thanks

  16. #16
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    yea i cant see any problem or errors occuring as you are only opening the workbook up.

    are you using imported data??

  17. #17
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Im just using sumproduct formulas to pull data from another workbook which does not need to be opened.

    I think this is working fine

  18. #18
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    ok then, good luck with it

    if you need any further help i wil happily help

  19. #19
    Forum Contributor thompsy121's Avatar
    Join Date
    09-25-2008
    Location
    Newcastle upon Tyne - UK
    MS-Off Ver
    Office 365
    Posts
    119
    Will do mate, thanks for all your advice


  20. #20
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    no probs glad to help

  21. #21
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    macro

    HI
    Try the following codes
    Please Login or Register  to view this content.
    Save this macro in a new file and run it.Enter the filename and filepath to be opened and closed. check if it is getting refreshed each time or not.
    Ravi

+ 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. Eliminating Save Dialog but still Saving Excel File
    By uzymedphys in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2008, 01:10 PM
  2. Macro for opening an external Batch file and closing the same at regular intervals.
    By Chintu Raju in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2008, 03:33 AM
  3. Automatic Excel File Closing
    By fiveoaks in forum Excel General
    Replies: 1
    Last Post: 10-31-2007, 09:22 AM
  4. Replies: 3
    Last Post: 10-13-2007, 04:58 AM
  5. excel closing - no error messages
    By kollin in forum Excel General
    Replies: 1
    Last Post: 08-17-2007, 03:00 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