Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems closing a workbook with VBA

Hi everyone

I coded a button on a userform with Application.Quit - all was fine.

I run into problems if more than one file is open as all the file
close when the code is run.

I changed the code to ThisWorkbook.close

This is OK if more than one file is open however if the workbook is th
only one open I am left with the blue bar, menu bar and toolbars at th
top of a grey screen when I run the code.

Is there a way of saying

If <if there is more than one file open Then
ThisWorkbook.Close
Else
Application.Quit
End If


Any Suggestions?

TIA

Kenny
Win ME and 2000
Office 97 and 200

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems closing a workbook with VBA

You can try:

Sub CloseBooks()

On Error GoTo OnlyOneOpen
If Len(Application.Workbooks(2).name) 0 Then
ThisWorkbook.Close
Exit Sub
End If
OnlyOneOpen: Application.Quit
End Sub


Haven't tested so I am not sure if it works but I belive it is OK.

Best Regards

Noo

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems closing a workbook with VBA

And of course I think you can substitute the "<if there is more than on
file open" in your equation by:

Workbooks.Count 1

Best Regards

Noo

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems closing a workbook with VBA

Thanks Nook

That did the trick - or so I thought - extensive testing revealed m
problem of the menu and toolbars remaining with a grey screen was du
to Personal.xls If I removed this from excel then ran my fil
everything was Ok - your assistance with workbooks.count solved m
problem with multiple files being open.

As a compromise I have added code to close Personal.xls when I open m
file. This isn't really fixing the bug but it was decided that this i
better than closing down to a grey screen.

Now I am trying to write If Personal.xls exists, close it! as a
present if Personal.xls does not exist I get an error (supperssed by o
Error Resume Next)

Many thanks again

Kenn

--
Message posted from http://www.ExcelForum.com

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
Help with closing down a workbook?? Don Excel Worksheet Functions 1 May 9th 05 04:05 AM
Closing workbook Ed Excel Programming 4 February 6th 04 03:41 PM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM
Closing a workbook Belinda Excel Programming 2 January 15th 04 01:27 PM
problems closing workbook Kevin Excel Programming 2 December 17th 03 08:26 AM


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