Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 13
Default Closing and reopening the same file

I need a macro to close an open file but without saving its changed content.
Then reopen it again. Hence, the macro will have to be able to read the
filename first and use that name to reopen it. Any help is much appreciated.

TIA
Tom


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Closing and reopening the same file

If you're running this from a different workbook, but want to close the
activeworkbook.

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
set wkbk = workbooks.open(filename:=wkbkfullname)
end with




Tom wrote:

I need a macro to close an open file but without saving its changed content.
Then reopen it again. Hence, the macro will have to be able to read the
filename first and use that name to reopen it. Any help is much appreciated.

TIA
Tom


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Closing and reopening the same file

It won't change the way the code works, but it looks more natural:

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
end with
set wkbk = workbooks.open(filename:=wkbkfullname)




Dave Peterson wrote:

If you're running this from a different workbook, but want to close the
activeworkbook.

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
set wkbk = workbooks.open(filename:=wkbkfullname)
end with



Tom wrote:

I need a macro to close an open file but without saving its changed content.
Then reopen it again. Hence, the macro will have to be able to read the
filename first and use that name to reopen it. Any help is much appreciated.

TIA
Tom


--

Dave Peterson


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 13
Default Closing and reopening the same file

Thank you Dave. That's wonderful. It did exactly what I hoped it would do.
Just a couple of questions:
1. Does Excel capture the name of the active document with the line,
wkbkfullname = .fullname ?
2. The use of dot (.) fascintes me. Where can I find out how else it can be
used? Am not a programmer.

TIA
Tom

"Dave Peterson" wrote in message
...
It won't change the way the code works, but it looks more natural:

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
end with
set wkbk = workbooks.open(filename:=wkbkfullname)




Dave Peterson wrote:

If you're running this from a different workbook, but want to close the
activeworkbook.

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
set wkbk = workbooks.open(filename:=wkbkfullname)
end with



Tom wrote:

I need a macro to close an open file but without saving its changed
content.
Then reopen it again. Hence, the macro will have to be able to read the
filename first and use that name to reopen it. Any help is much
appreciated.

TIA
Tom


--

Dave Peterson


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Closing and reopening the same file

Check VBA's help for the With statement.

It makes coding easier to type and easier to read.

with workbooks("someworkbookname.xls").worksheets("some name")
.range("a1").value = "hi"
.range("b1:b99").clearcontents
.protect
end with

is easier to type and read than:


workbooks("someworkbookname.xls").worksheets("some name").range("a1").value _
= "hi"

workbooks("someworkbookname.xls").worksheets("some name").range("b1:b99") _
.clearcontents

workbooks("someworkbookname.xls").worksheets("some name").protect

The leading dot means that that property or method (like an adjective and or
verb) belongs to the object that was used in the preceding With statement. In
this case a range object on a certain worksheet in a specific workbook.

And so .fullname belongs to the object Activeworkbook.

..fullname will return the drive\path\filename.ext

..name will return only the filename.ext portion.




Tom wrote:

Thank you Dave. That's wonderful. It did exactly what I hoped it would do.
Just a couple of questions:
1. Does Excel capture the name of the active document with the line,
wkbkfullname = .fullname ?
2. The use of dot (.) fascintes me. Where can I find out how else it can be
used? Am not a programmer.

TIA
Tom

"Dave Peterson" wrote in message
...
It won't change the way the code works, but it looks more natural:

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
end with
set wkbk = workbooks.open(filename:=wkbkfullname)




Dave Peterson wrote:

If you're running this from a different workbook, but want to close the
activeworkbook.

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
set wkbk = workbooks.open(filename:=wkbkfullname)
end with



Tom wrote:

I need a macro to close an open file but without saving its changed
content.
Then reopen it again. Hence, the macro will have to be able to read the
filename first and use that name to reopen it. Any help is much
appreciated.

TIA
Tom

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 13
Default Closing and reopening the same file

Thanks once again. By the way, when I named your original set of codes
"Reload" located in Personal.xls, and then called it inside another
procedure with:
Application.Run "'Personal.xls'!Module10.Reload"
the active document just closed but did not reopen. I wonder why it did not
execute the last line:
set wkbk = workbooks.open(filename:=wkbkfullname)
?

Tom

"Dave Peterson" wrote in message
...
Check VBA's help for the With statement.

It makes coding easier to type and easier to read.

with workbooks("someworkbookname.xls").worksheets("some name")
.range("a1").value = "hi"
.range("b1:b99").clearcontents
.protect
end with

is easier to type and read than:


workbooks("someworkbookname.xls").worksheets("some name").range("a1").value
_
= "hi"

workbooks("someworkbookname.xls").worksheets("some name").range("b1:b99") _
.clearcontents

workbooks("someworkbookname.xls").worksheets("some name").protect

The leading dot means that that property or method (like an adjective and
or
verb) belongs to the object that was used in the preceding With statement.
In
this case a range object on a certain worksheet in a specific workbook.

And so .fullname belongs to the object Activeworkbook.

.fullname will return the drive\path\filename.ext

.name will return only the filename.ext portion.




Tom wrote:

Thank you Dave. That's wonderful. It did exactly what I hoped it would
do.
Just a couple of questions:
1. Does Excel capture the name of the active document with the line,
wkbkfullname = .fullname ?
2. The use of dot (.) fascintes me. Where can I find out how else it can
be
used? Am not a programmer.

TIA
Tom

"Dave Peterson" wrote in message
...
It won't change the way the code works, but it looks more natural:

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
end with
set wkbk = workbooks.open(filename:=wkbkfullname)




Dave Peterson wrote:

If you're running this from a different workbook, but want to close
the
activeworkbook.

Dim wkbkFullName as string
dim wkbk as workbook
with activeworkbook
wkbkfullname = .fullname
.close savechanges:=false
set wkbk = workbooks.open(filename:=wkbkfullname)
end with



Tom wrote:

I need a macro to close an open file but without saving its changed
content.
Then reopen it again. Hence, the macro will have to be able to read
the
filename first and use that name to reopen it. Any help is much
appreciated.

TIA
Tom

--

Dave Peterson

--

Dave Peterson


--

Dave Peterson



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
Cells widen after saving and reopening file Sigi Rindler Excel Discussion (Misc queries) 2 November 23rd 06 12:03 AM
i zoom to 75% on Excel but returns to 100% reopening file dennis at leapley Excel Worksheet Functions 0 November 17th 06 03:16 PM
Legend box position resetting when reopening file donger Charts and Charting in Excel 0 May 19th 06 08:44 PM
My comments reformat after closing and reopening. Picman Excel Discussion (Misc queries) 0 May 25th 05 04:34 PM
Filter changes upon reopening file! b1 Excel Discussion (Misc queries) 1 December 3rd 04 03:20 AM


All times are GMT +1. The time now is 08:40 AM.

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

About Us

"It's about Microsoft Excel"