![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP, Administrator
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,679
|
I currently have a blank workbook with nothing but the code, so that when I open it, it will run the macro and open certain sheets.
Can I add on to this so that after it is finished running, it will close the original worksheet? This is what I currently have: Code:
Private Sub Workbook_Open() On Error GoTo myErr ChDir "directory" Workbooks.Open "workbook1.xls" Workbooks.Open "workbook2.xls" Which = Application.GetOpenFilename(MultiSelect:=True) 'Which now contains an array of file names which you can enumerate through For I = 1 To UBound(Which) Workbooks.Open Which(I) Next End myErr: End Sub |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#3 | |
|
MrExcel MVP, Administrator
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,679
|
Quote:
[ This Message was edited by: Von Pookie on 2002-03-08 08:46 ] |
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
At the end of your code, you can put a line like this:
ThisWorkbook.Close False The false is so that it won't save changes (and won't prompt you). If you do want to save changes to this workbook, then change false to true. HTH, Russell [ This Message was edited by: Russell Hauf on 2002-03-08 08:49 ] |
|
|
|
|
|
#5 |
|
MrExcel MVP, Administrator
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,679
|
Looks like it worked!
Thanks! |
|
|
|
|
|
#6 | ||
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
Code:
Private Sub Workbook_Open() Dim CurrentWorkbook As String On Error GoTo myErr ChDir "directory" Workbooks.Open "workbook1.xls" Workbooks.Open "workbook2.xls" which = Application.GetOpenFilename(MultiSelect:=True) 'Which now contains an array of file names which you can enumerate through For I = 1 To UBound(which) Workbooks.Open which(I) CurrentWorkbook = ActiveWorkbook.Name 'whatever macro you want to run. 'this is where I was getting confused Workbooks(CurrentWorkbook).Close (True) Next End myErr: End Sub
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
||
|
|
|
|
|
#7 | |
|
MrExcel MVP, Administrator
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,679
|
Quote:
I have a blank workbook with the code to open 3 other workbooks. After those 3 were open, I simply wanted to close the blank one with the code, but leave the ones I told it to open. Sorry about that! _________________ "What am I, a magnet for these idiots?" --Pearl Forrester, MST3K [ This Message was edited by: Von Pookie on 2002-03-08 09:12 ] |
|
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
I thought you described it fine with this sentence from your original post:
"Can I add on to this so that after it is finished running, it will close the original worksheet?" Glad I could help, Russell |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|