Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default if its open...close it

i have sheet workbook "register" and "commission"
i have a macro in "register" that closes commission.
however i need a if statement that say if "commission" isnt open...dont run
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default if its open...close it

Dim bk as Workbook
On error resume next
set bk = workbooks("Commission.xls")
On error goto 0
if bk is nothing then exit sub

--
Regards,
Tom Ogilvy


"choice" wrote in message
...
i have sheet workbook "register" and "commission"
i have a macro in "register" that closes commission.
however i need a if statement that say if "commission" isnt open...dont

run


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default if its open...close it

If all you're doing is closing "commission":

On Error Resume Next
Workbooks("commission").Close SaveChanges:=False
On Error GoTo 0


In article ,
choice wrote:

i have sheet workbook "register" and "commission"
i have a macro in "register" that closes commission.
however i need a if statement that say if "commission" isnt open...dont run

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default if its open...close it

If the workbook Commission had the .xls extension, I think I'd specify it:

On Error Resume Next
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0



JE McGimpsey wrote:

If all you're doing is closing "commission":

On Error Resume Next
Workbooks("commission").Close SaveChanges:=False
On Error GoTo 0


In article ,
choice wrote:

i have sheet workbook "register" and "commission"
i have a macro in "register" that closes commission.
however i need a if statement that say if "commission" isnt open...dont run


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default if its open...close it

Thanks, David. I occasionally forget which newsgroup I'm on - MacXL
files don't require extensions, of course, nor are they automatically
added by the OS.


In article , Dave Peterson
wrote:

If the workbook Commission had the .xls extension, I think I'd specify it:



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default if its open...close it

"Dave Peterson" skrev i melding
...
If the workbook Commission had the .xls extension, I think I'd specify it:

On Error Resume Next
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0


That will err if the file extension is hidden. To be safe, use both:

On Error Resume Next
Workbooks("commission").Close SaveChanges:=False
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0

Best wishes Harald


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default if its open...close it

I just tried this in win98 with extensions hidden and visible.

It worked ok both ways. I've never seen the "commission.xls" version fail.

(I've never seen the "commission" version fail, either--but since I've been
reading the newsgroup, I always include the extension <vbg.)

I have seen posts where just adding the extension makes a routine work.

Harald Staff wrote:

"Dave Peterson" skrev i melding
...
If the workbook Commission had the .xls extension, I think I'd specify it:

On Error Resume Next
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0


That will err if the file extension is hidden. To be safe, use both:

On Error Resume Next
Workbooks("commission").Close SaveChanges:=False
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0

Best wishes Harald


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default if its open...close it

Hi Dave

My Windows XP Home has not "hide known file extensions" enabled. But it has
all Excel versions since 5 on it, which may of course confuse it a little.
This is what happens he

I open Excel2003. It generates an empty Book1. Caption says so.
Then I open Excel 2000. It generates an empty Book2 ! Now why is that ?
Then I open Excel XP. It generates an empty Book3. There's a pattern here...

I return to 2003. I save its file as "C:\Temp\Book1". Suddenly the caption
reads "Book1.xls". Then I run

Sub test()
MsgBox Workbooks("Book1.xls").Name
MsgBox Workbooks("Book1").Name
End Sub


and it errs on the non-.xls line. Now I go to Excel XP, Book3 is not saved
there, and run

Sub test()
MsgBox Workbooks("Book3.xls").Name
MsgBox Workbooks("Book3").Name
End Sub

It errs on the .xls line.
So everything behaves unexpected, but more important, it does not work both
ways. So my advice is still, "To be safe, use both".

And to be honest I really miss Win98 a lot, it is a no-nonsense OS. I use
WinXP only because I need an OS handles larger hard drives than 98 was
capable of and that runs Visual Basic.

Best wishes Harald

"Dave Peterson" skrev i melding
...
I just tried this in win98 with extensions hidden and visible.

It worked ok both ways. I've never seen the "commission.xls" version

fail.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default if its open...close it

Using the extension always works, regardless of the setting.

--
Regards,
Tom Ogilvy

"Harald Staff" wrote in message
...
"Dave Peterson" skrev i melding
...
If the workbook Commission had the .xls extension, I think I'd specify

it:

On Error Resume Next
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0


That will err if the file extension is hidden. To be safe, use both:

On Error Resume Next
Workbooks("commission").Close SaveChanges:=False
Workbooks("commission.xls").Close SaveChanges:=False
On Error GoTo 0

Best wishes Harald




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 do I close all open spreadsheets at once? cbh Excel Discussion (Misc queries) 13 January 12th 08 11:30 PM
Open then Close Markus Excel Programming 2 July 14th 04 07:44 PM
On Open/On Close Jeff Excel Programming 3 June 9th 04 10:23 PM
Close Open Workbook David Coleman Excel Programming 1 December 30th 03 05:53 PM
Close database if it is open Tod Excel Programming 0 July 18th 03 07:19 PM


All times are GMT +1. The time now is 09:33 PM.

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

About Us

"It's about Microsoft Excel"