Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Closing a workbook programmatically

I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

......
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
.....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Closing a workbook programmatically

Try with

currentBook.Close

instead

--
Regards

Juan Pablo González

"Raul" wrote in message
...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Closing a workbook programmatically

Hi Raul

Try this

Sub test()
Dim destWB As Workbook
Set destWB = Workbooks.Open("K:\AAAA\BBBB\CCCC\excelfile.xls")
MsgBox "By"
destWB.Close True ' false = not save and true = save
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Raul" wrote in message ...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Closing a workbook programmatically

Thanks a bunch. I found the error in my code. The code
wasn't getting the name of the file I wanted to close.
After I added
"WorkBookName = Application.ActiveWorkbook.Name"
and in the code and then used WorkBookName instead of
currentBook in the following statement it worked
"Workbooks(WorkBookName).Close SaveChanges:=False"

I'll try your suggestion also. I was dimensioning
currentBook As Excel.WorkBook

Is this correct?

Thanks again

-----Original Message-----
Try with

currentBook.Close

instead

--
Regards

Juan Pablo González

"Raul" wrote in

message
...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the

file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Closing a workbook programmatically

Yep, that's correct. You're working with the object (The workbook) directly
instead of accessing the collection.

--
Regards

Juan Pablo González

"Raul" wrote in message
...
Thanks a bunch. I found the error in my code. The code
wasn't getting the name of the file I wanted to close.
After I added
"WorkBookName = Application.ActiveWorkbook.Name"
and in the code and then used WorkBookName instead of
currentBook in the following statement it worked
"Workbooks(WorkBookName).Close SaveChanges:=False"

I'll try your suggestion also. I was dimensioning
currentBook As Excel.WorkBook

Is this correct?

Thanks again

-----Original Message-----
Try with

currentBook.Close

instead

--
Regards

Juan Pablo González

"Raul" wrote in

message
...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the

file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Closing a workbook programmatically

Thanks a bunch. I found the error in my code. The code
wasn't getting the name of the file I wanted to close.
After I added
"WorkBookName = Application.ActiveWorkbook.Name"
and in the code and then used WorkBookName instead of
currentBook in the following statement it worked
"Workbooks(WorkBookName).Close SaveChanges:=False"

Your code snippet answered another question I had about
the Dim statement. Does the Set destWB = Workbooks.Open
do more than a plain Workbooks.Open command?

Thanks,
Raul


-----Original Message-----
Hi Raul

Try this

Sub test()
Dim destWB As Workbook
Set destWB = Workbooks.Open

("K:\AAAA\BBBB\CCCC\excelfile.xls")
MsgBox "By"
destWB.Close True ' false = not save and true = save
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Raul" wrote in

message ...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the

file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Closing a workbook programmatically

Thanks,
Raul
-----Original Message-----
Yep, that's correct. You're working with the object

(The workbook) directly
instead of accessing the collection.

--
Regards

Juan Pablo González

"Raul" wrote in

message
...
Thanks a bunch. I found the error in my code. The code
wasn't getting the name of the file I wanted to close.
After I added
"WorkBookName = Application.ActiveWorkbook.Name"
and in the code and then used WorkBookName instead of
currentBook in the following statement it worked
"Workbooks(WorkBookName).Close SaveChanges:=False"

I'll try your suggestion also. I was dimensioning
currentBook As Excel.WorkBook

Is this correct?

Thanks again

-----Original Message-----
Try with

currentBook.Close

instead

--
Regards

Juan Pablo González

"Raul" wrote in

message
...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do

it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the

file I
want to close. I also have other workbooks open that

I
don't want closed.

Thanks,
Raul



.



.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Closing a workbook programmatically

Hi Raul

Does the Set destWB = Workbooks.Open
do more than a plain Workbooks.Open command?


It will open and set a reference to the file
In your code you use two lines to do this



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Raul" wrote in message ...
Thanks a bunch. I found the error in my code. The code
wasn't getting the name of the file I wanted to close.
After I added
"WorkBookName = Application.ActiveWorkbook.Name"
and in the code and then used WorkBookName instead of
currentBook in the following statement it worked
"Workbooks(WorkBookName).Close SaveChanges:=False"

Your code snippet answered another question I had about
the Dim statement. Does the Set destWB = Workbooks.Open
do more than a plain Workbooks.Open command?

Thanks,
Raul


-----Original Message-----
Hi Raul

Try this

Sub test()
Dim destWB As Workbook
Set destWB = Workbooks.Open

("K:\AAAA\BBBB\CCCC\excelfile.xls")
MsgBox "By"
destWB.Close True ' false = not save and true = save
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Raul" wrote in

message ...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the

file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul



.



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
How to programmatically check if a workbook is protected t? uno@korsmaa Excel Programming 2 September 15th 04 09:23 PM
Closing VBA editior programmatically Shatin Excel Programming 2 January 28th 04 06:12 PM
How to install a workbook as a shortcut on the desktop programmatically Belinda Excel Programming 1 January 23rd 04 07:11 AM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM
Close Workbook Programmatically Lucy[_2_] Excel Programming 3 December 30th 03 08:17 PM


All times are GMT +1. The time now is 06:39 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"