Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Everytime i close an excel file, it creates a new backup file | Excel Discussion (Misc queries) | |||
Close file and run macro from newly opened file | Excel Programming | |||
Close Current File Then Open New file | Excel Programming | |||
VBA - on a button event, open another closed file, post changes, close file | Excel Programming | |||
Automate open file, update links, run macro, close and save file | Excel Programming |