Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Sheet to close

Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Sheet to close


Activesheet.name=

try this simpler version
Sub CloseifMaster()
If ActiveSheet.Name = "Master" Then
With ActiveWorkbook
'one dot only
.Save
.Close
End With
End If
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"oldjay" wrote in message
...
Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Sheet to close

If wsShtToSave.Name = "Master" Then


Gord Dibben MS Excel MVP


On Sun, 13 Dec 2009 08:30:01 -0800, oldjay
wrote:

Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Sheet to close

Hi,

Why not make it simpler

If ActiveSheet.Name = "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If

Mike

"oldjay" wrote:

Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Sheet to close

Thank I will use your code.
Can you tell me why mine didn't work?

"Mike H" wrote:

Hi,

Why not make it simpler

If ActiveSheet.Name = "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If

Mike

"oldjay" wrote:

Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Sheet to close

You are comparing a worksheet object to a text value. Do this instead:

If wsShtToSave.Name = "Master" Then

Robert Flanagan
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"oldjay" wrote in message
...
Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Sheet to close

Can you tell me why mine didn't work?

When you used the Set key word, you created an OBJECT varable. You then
tried to compare the object to a property (text string) name. That wont
work.

Object variables apply to Object items like Workbook, Sheet, Range, etc.
Regular variables apply to properties like text, values, fonts, etc.

When making comparisons, be sure they are the same data type and class.

Exmpl:

If wsShtToSave = Sheets('Master") 'compares objects

or

If wsShtToSave.Name = "Master" 'compares properties

Either of the above would work.



"oldjay" wrote in message
...
Thank I will use your code.
Can you tell me why mine didn't work?

"Mike H" wrote:

Hi,

Why not make it simpler

If ActiveSheet.Name = "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If

Mike

"oldjay" wrote:

Why won't this work?

oldjayo

Sub test()

Dim wsShtToSave As Worksheet
Set wsShtToSave = ActiveSheet
If wsShtToSave= "Master" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
End Sub



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
Ecape key to close/exit sheet count Excel Programming 2 March 31st 09 03:50 PM
how to use Application.VLookup on close sheet Dan Excel Programming 2 June 4th 08 10:28 AM
Vlookup from close sheet via VBA Dan Excel Programming 4 June 4th 08 10:28 AM
Before close - not always deleting sheet- WHY?? Patti[_2_] Excel Programming 2 August 2nd 05 05:08 PM
Hanging on sheet close Jesse[_4_] Excel Programming 2 December 4th 03 09:21 AM


All times are GMT +1. The time now is 07:16 AM.

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"