Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Code to close and reopen file

Looking to have a bit of code that will close the file it works on without
saving it and then reopen the same file.

I have a file (template.xls) which has a macro which runs on opening. Users
can then manipulate data and save the results to a given file. Without having
to blank all of the areas used for the data manipulation is there a way of
closing the template.xls file and then reopening it?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Code to close and reopen file


FName = "C:\temp\book1.xls""

''open workbook the 1st time
set oldbk = workbooks.open(filename:=FName)

'close file without making any changes
oldbk.close savechanges:=false

'open file a second time
set oldbk = workbooks.open(filename:=FName)


"Mr Bunj" wrote:

Looking to have a bit of code that will close the file it works on without
saving it and then reopen the same file.

I have a file (template.xls) which has a macro which runs on opening. Users
can then manipulate data and save the results to a given file. Without having
to blank all of the areas used for the data manipulation is there a way of
closing the template.xls file and then reopening it?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Code to close and reopen file

Does the macro stop running when the file is closed?

If so how would it know to open itself again?


"Joel" wrote:


FName = "C:\temp\book1.xls""

''open workbook the 1st time
set oldbk = workbooks.open(filename:=FName)

'close file without making any changes
oldbk.close savechanges:=false

'open file a second time
set oldbk = workbooks.open(filename:=FName)


"Mr Bunj" wrote:

Looking to have a bit of code that will close the file it works on without
saving it and then reopen the same file.

I have a file (template.xls) which has a macro which runs on opening. Users
can then manipulate data and save the results to a given file. Without having
to blank all of the areas used for the data manipulation is there a way of
closing the template.xls file and then reopening it?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Code to close and reopen file

A macro only stop running when Thisworkbook is closed. Not when other
workbooks are closed. Thisworkbook referes to the workbook where the macro
is located. A template is a second workbook that you open from Thisworkbook.


"Mr Bunj" wrote:

Does the macro stop running when the file is closed?

If so how would it know to open itself again?


"Joel" wrote:


FName = "C:\temp\book1.xls""

''open workbook the 1st time
set oldbk = workbooks.open(filename:=FName)

'close file without making any changes
oldbk.close savechanges:=false

'open file a second time
set oldbk = workbooks.open(filename:=FName)


"Mr Bunj" wrote:

Looking to have a bit of code that will close the file it works on without
saving it and then reopen the same file.

I have a file (template.xls) which has a macro which runs on opening. Users
can then manipulate data and save the results to a given file. Without having
to blank all of the areas used for the data manipulation is there a way of
closing the template.xls file and then reopening it?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Code to close and reopen file

Why don't you just save your file as template file (*.XLT) without any data
filled in at all. That would negate the need for an open/close/reopen macro.
--
Kevin Backmann


"Mr Bunj" wrote:

Looking to have a bit of code that will close the file it works on without
saving it and then reopen the same file.

I have a file (template.xls) which has a macro which runs on opening. Users
can then manipulate data and save the results to a given file. Without having
to blank all of the areas used for the data manipulation is there a way of
closing the template.xls file and then reopening it?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Code to close and reopen file

Have solved this one by writing a function which mimics the auto_open
function and then using the following as an option on their menu

Application.OnTime Now + TimeValue("00:00:02"), "on_opening"
ThisWorkbook.Close SaveChanges:=False


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save file close and reopen Graham[_2_] Excel Programming 3 April 1st 08 10:03 AM
How to code the Macro to save and close a file? Eric Excel Discussion (Misc queries) 7 June 10th 07 03:28 PM
How to show gridlines when I close & reopen without having to go Shorty Excel Discussion (Misc queries) 1 July 16th 06 10:44 PM
create chart /table excel-save, close & reopen colors change? Why Anne Charts and Charting in Excel 1 July 4th 06 09:16 PM
VBA code to automatically close file Kevin Excel Programming 4 November 6th 03 04:18 PM


All times are GMT +1. The time now is 07:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"