PC Review


Reply
Thread Tools Rate Thread

Code to close and reopen file

 
 
Mr Bunj
Guest
Posts: n/a
 
      16th Jun 2008
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?
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      16th Jun 2008

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?

 
Reply With Quote
 
Mr Bunj
Guest
Posts: n/a
 
      16th Jun 2008
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?

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      16th Jun 2008
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?

 
Reply With Quote
 
Kevin B
Guest
Posts: n/a
 
      16th Jun 2008
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?

 
Reply With Quote
 
Mr Bunj
Guest
Posts: n/a
 
      16th Jun 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code will only run once unless i close and reopen form Blakey300 Microsoft Access Forms 5 13th Mar 2009 02:25 PM
Save file close and reopen Graham Microsoft Excel Programming 3 1st Apr 2008 10:03 AM
VBA Code dosent run after close & reopen Jagdip Singh Ajimal Microsoft Excel Discussion 2 25th Apr 2005 01:35 PM
Re: Open a File, Close it and upon Reopen: Error Dave Peterson Microsoft Excel Misc 0 27th Aug 2003 12:54 AM
Re: Open a File, Close it and upon Reopen: Error Ron de Bruin Microsoft Excel Misc 0 26th Aug 2003 04:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.