![]() |
Close File
How do I get an excel workbook to close using a macro?
I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
Close File
Workbooks(filename).Close
such as Workbooks("myBook.xls").Close Note that if the file is 'dirty' you will get prompted to save it. You can either preced it with Application.DisplayAlerts = False to avoid the message, or avoid the save with Workbooks("myBook.xls").Close SaveChanges:=False Application.Quit would cause Excel to shutdown. -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... How do I get an excel workbook to close using a macro? I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
Close File
I tried that too. The problem is the file is a variable name, so do I still
put the quotes? Thanks for your help. "Bob Phillips" wrote: Workbooks(filename).Close such as Workbooks("myBook.xls").Close Note that if the file is 'dirty' you will get prompted to save it. You can either preced it with Application.DisplayAlerts = False to avoid the message, or avoid the save with Workbooks("myBook.xls").Close SaveChanges:=False Application.Quit would cause Excel to shutdown. -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... How do I get an excel workbook to close using a macro? I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
Close File
No, I showed that, just use
Workbooks(filename).Close where filename would be defined such as filename = "myBook.xls" -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... I tried that too. The problem is the file is a variable name, so do I still put the quotes? Thanks for your help. "Bob Phillips" wrote: Workbooks(filename).Close such as Workbooks("myBook.xls").Close Note that if the file is 'dirty' you will get prompted to save it. You can either preced it with Application.DisplayAlerts = False to avoid the message, or avoid the save with Workbooks("myBook.xls").Close SaveChanges:=False Application.Quit would cause Excel to shutdown. -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... How do I get an excel workbook to close using a macro? I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
Close File
This is what I have. I'm not sure what to do with it. It works by having the
user open a file, but then the file needs to be closed. Sub MacroOpenFile() Dim fileToOpen fileToOpen = Application.GetOpenFilename("Excel Files (*.csv), *.csv") If fileToOpen < False Then Workbooks.Open fileToOpen End If Sheets.Select Sheets.Copy Befo=Workbooks("MACRO").Sheets(1) Workbooks(fileToOpen).Close "Bob Phillips" wrote: No, I showed that, just use Workbooks(filename).Close where filename would be defined such as filename = "myBook.xls" -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... I tried that too. The problem is the file is a variable name, so do I still put the quotes? Thanks for your help. "Bob Phillips" wrote: Workbooks(filename).Close such as Workbooks("myBook.xls").Close Note that if the file is 'dirty' you will get prompted to save it. You can either preced it with Application.DisplayAlerts = False to avoid the message, or avoid the save with Workbooks("myBook.xls").Close SaveChanges:=False Application.Quit would cause Excel to shutdown. -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... How do I get an excel workbook to close using a macro? I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
Close File
If the file is the current file:
ActiveWorkbook.Close SaveChanges:=True (or False) If not, make it active first: Windows(filename).Activate "MSHO" wrote: How do I get an excel workbook to close using a macro? I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
Close File
Sub MacroOpenFile()
Dim fileToOpen Dim oWb As Workbook fileToOpen = Application.GetOpenFilename("Excel Files (*.csv), *.csv") If fileToOpen < False Then Workbooks.Open fileToOpen End If Set oWb = ActiveWorkbook Sheets.Select Sheets.Copy Befo=Workbooks("MACRO.xls").Sheets(1) oWb.Close -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... This is what I have. I'm not sure what to do with it. It works by having the user open a file, but then the file needs to be closed. Sub MacroOpenFile() Dim fileToOpen fileToOpen = Application.GetOpenFilename("Excel Files (*.csv), *.csv") If fileToOpen < False Then Workbooks.Open fileToOpen End If Sheets.Select Sheets.Copy Befo=Workbooks("MACRO").Sheets(1) Workbooks(fileToOpen).Close "Bob Phillips" wrote: No, I showed that, just use Workbooks(filename).Close where filename would be defined such as filename = "myBook.xls" -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... I tried that too. The problem is the file is a variable name, so do I still put the quotes? Thanks for your help. "Bob Phillips" wrote: Workbooks(filename).Close such as Workbooks("myBook.xls").Close Note that if the file is 'dirty' you will get prompted to save it. You can either preced it with Application.DisplayAlerts = False to avoid the message, or avoid the save with Workbooks("myBook.xls").Close SaveChanges:=False Application.Quit would cause Excel to shutdown. -- HTH Bob Phillips (remove nothere from email address if mailing direct) "MSHO" wrote in message ... How do I get an excel workbook to close using a macro? I tried Application(filename).Quit but it didn't work. Thanks Mikayla |
All times are GMT +1. The time now is 11:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com