#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
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
Everytime i close an excel file, it creates a new backup file p Excel Discussion (Misc queries) 3 November 22nd 07 08:13 AM
Close file and run macro from newly opened file Pradip Jain Excel Programming 1 April 23rd 05 11:39 PM
Close Current File Then Open New file Steve Roberts Excel Programming 1 March 31st 05 02:08 AM
VBA - on a button event, open another closed file, post changes, close file Fio Excel Programming 0 March 1st 04 01:08 PM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


All times are GMT +1. The time now is 03:28 PM.

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

About Us

"It's about Microsoft Excel"