Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Cells widen after saving and reopening file | Excel Discussion (Misc queries) | |||
i zoom to 75% on Excel but returns to 100% reopening file | Excel Worksheet Functions | |||
Legend box position resetting when reopening file | Charts and Charting in Excel | |||
My comments reformat after closing and reopening. | Excel Discussion (Misc queries) | |||
Filter changes upon reopening file! | Excel Discussion (Misc queries) |