PC Review


Reply
Thread Tools Rate Thread

can't hide workbook or trap error

 
 
=?Utf-8?B?QWxsZW5fTg==?=
Guest
Posts: n/a
 
      5th Apr 2007
I'm trying to hide the workbook that contains my macro library. This used to
work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
produces the error "Object doesn't support this property or method" and the
error is not trapped.

Sub auto_open()

Dim i&, wb

For i& = 1 To Workbooks.Count
Set wb = Workbooks(i&)
If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
Next i&

Exit Sub

HideWB:

On Error GoTo SkipHide
wb.Visible = False
SkipHide:
On Error GoTo 0
Return

End Sub

What could be going wrong?

 
Reply With Quote
 
 
 
 
Bob Flanagan
Guest
Posts: n/a
 
      5th Apr 2007
Instead of wb.visible = false, you want to hide the window:

Windows(ThisWorkbook.Name).Visible = False

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


"Allen_N" <(E-Mail Removed)> wrote in message
news:66A406C6-71B0-4D26-BD4C-(E-Mail Removed)...
> I'm trying to hide the workbook that contains my macro library. This used
> to
> work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> produces the error "Object doesn't support this property or method" and
> the
> error is not trapped.
>
> Sub auto_open()
>
> Dim i&, wb
>
> For i& = 1 To Workbooks.Count
> Set wb = Workbooks(i&)
> If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> Next i&
>
> Exit Sub
>
> HideWB:
>
> On Error GoTo SkipHide
> wb.Visible = False
> SkipHide:
> On Error GoTo 0
> Return
>
> End Sub
>
> What could be going wrong?
>



 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      5th Apr 2007
I can't find anything that says the visible property applies to workbooks.

"Allen_N" wrote:

> I'm trying to hide the workbook that contains my macro library. This used to
> work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> produces the error "Object doesn't support this property or method" and the
> error is not trapped.
>
> Sub auto_open()
>
> Dim i&, wb
>
> For i& = 1 To Workbooks.Count
> Set wb = Workbooks(i&)
> If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> Next i&
>
> Exit Sub
>
> HideWB:
>
> On Error GoTo SkipHide
> wb.Visible = False
> SkipHide:
> On Error GoTo 0
> Return
>
> End Sub
>
> What could be going wrong?
>

 
Reply With Quote
 
=?Utf-8?B?QWxsZW5fTg==?=
Guest
Posts: n/a
 
      5th Apr 2007
Thanks, Bob.

Now I'm trying:

Windows(wb.Name).Visible = False

but I still get "Object doesn't support this property or method".

I confirmed that wb.Name = "PERSONAL.XLS".


"Bob Flanagan" wrote:

> Instead of wb.visible = false, you want to hide the window:
>
> Windows(ThisWorkbook.Name).Visible = False
>
> Bob Flanagan
> Macro Systems
> http://www.add-ins.com
> Productivity add-ins and downloadable books on VB macros for Excel
>
>
> "Allen_N" <(E-Mail Removed)> wrote in message
> news:66A406C6-71B0-4D26-BD4C-(E-Mail Removed)...
> > I'm trying to hide the workbook that contains my macro library. This used
> > to
> > work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> > produces the error "Object doesn't support this property or method" and
> > the
> > error is not trapped.
> >
> > Sub auto_open()
> >
> > Dim i&, wb
> >
> > For i& = 1 To Workbooks.Count
> > Set wb = Workbooks(i&)
> > If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> > If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> > Next i&
> >
> > Exit Sub
> >
> > HideWB:
> >
> > On Error GoTo SkipHide
> > wb.Visible = False
> > SkipHide:
> > On Error GoTo 0
> > Return
> >
> > End Sub
> >
> > What could be going wrong?
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?QWxsZW5fTg==?=
Guest
Posts: n/a
 
      5th Apr 2007
You're right. Serves me right for trapping an error and not testing it.


"JLGWhiz" wrote:

> I can't find anything that says the visible property applies to workbooks.
>
> "Allen_N" wrote:
>
> > I'm trying to hide the workbook that contains my macro library. This used to
> > work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> > produces the error "Object doesn't support this property or method" and the
> > error is not trapped.
> >
> > Sub auto_open()
> >
> > Dim i&, wb
> >
> > For i& = 1 To Workbooks.Count
> > Set wb = Workbooks(i&)
> > If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> > If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> > Next i&
> >
> > Exit Sub
> >
> > HideWB:
> >
> > On Error GoTo SkipHide
> > wb.Visible = False
> > SkipHide:
> > On Error GoTo 0
> > Return
> >
> > End Sub
> >
> > What could be going wrong?
> >

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Apr 2007
This may get you over the hump:

Dim wkbk As Workbook
Dim myWindow As Window
Set wkbk = ActiveWorkbook
For Each myWindow In wkbk.Windows
myWindow.Visible = False
Next myWindow



Allen_N wrote:
>
> Thanks, Bob.
>
> Now I'm trying:
>
> Windows(wb.Name).Visible = False
>
> but I still get "Object doesn't support this property or method".
>
> I confirmed that wb.Name = "PERSONAL.XLS".
>
> "Bob Flanagan" wrote:
>
> > Instead of wb.visible = false, you want to hide the window:
> >
> > Windows(ThisWorkbook.Name).Visible = False
> >
> > Bob Flanagan
> > Macro Systems
> > http://www.add-ins.com
> > Productivity add-ins and downloadable books on VB macros for Excel
> >
> >
> > "Allen_N" <(E-Mail Removed)> wrote in message
> > news:66A406C6-71B0-4D26-BD4C-(E-Mail Removed)...
> > > I'm trying to hide the workbook that contains my macro library. This used
> > > to
> > > work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> > > produces the error "Object doesn't support this property or method" and
> > > the
> > > error is not trapped.
> > >
> > > Sub auto_open()
> > >
> > > Dim i&, wb
> > >
> > > For i& = 1 To Workbooks.Count
> > > Set wb = Workbooks(i&)
> > > If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> > > If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> > > Next i&
> > >
> > > Exit Sub
> > >
> > > HideWB:
> > >
> > > On Error GoTo SkipHide
> > > wb.Visible = False
> > > SkipHide:
> > > On Error GoTo 0
> > > Return
> > >
> > > End Sub
> > >
> > > What could be going wrong?
> > >

> >
> >
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?QWxsZW5fTg==?=
Guest
Posts: n/a
 
      5th Apr 2007
Nope. debugging reveals that ActiveWorkbook is Nothing.

"Dave Peterson" wrote:

> This may get you over the hump:
>
> Dim wkbk As Workbook
> Dim myWindow As Window
> Set wkbk = ActiveWorkbook
> For Each myWindow In wkbk.Windows
> myWindow.Visible = False
> Next myWindow
>
>
>
> Allen_N wrote:
> >
> > Thanks, Bob.
> >
> > Now I'm trying:
> >
> > Windows(wb.Name).Visible = False
> >
> > but I still get "Object doesn't support this property or method".
> >
> > I confirmed that wb.Name = "PERSONAL.XLS".
> >
> > "Bob Flanagan" wrote:
> >
> > > Instead of wb.visible = false, you want to hide the window:
> > >
> > > Windows(ThisWorkbook.Name).Visible = False
> > >
> > > Bob Flanagan
> > > Macro Systems
> > > http://www.add-ins.com
> > > Productivity add-ins and downloadable books on VB macros for Excel
> > >
> > >
> > > "Allen_N" <(E-Mail Removed)> wrote in message
> > > news:66A406C6-71B0-4D26-BD4C-(E-Mail Removed)...
> > > > I'm trying to hide the workbook that contains my macro library. This used
> > > > to
> > > > work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> > > > produces the error "Object doesn't support this property or method" and
> > > > the
> > > > error is not trapped.
> > > >
> > > > Sub auto_open()
> > > >
> > > > Dim i&, wb
> > > >
> > > > For i& = 1 To Workbooks.Count
> > > > Set wb = Workbooks(i&)
> > > > If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> > > > If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> > > > Next i&
> > > >
> > > > Exit Sub
> > > >
> > > > HideWB:
> > > >
> > > > On Error GoTo SkipHide
> > > > wb.Visible = False
> > > > SkipHide:
> > > > On Error GoTo 0
> > > > Return
> > > >
> > > > End Sub
> > > >
> > > > What could be going wrong?
> > > >
> > >
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
=?Utf-8?B?QWxsZW5fTg==?=
Guest
Posts: n/a
 
      5th Apr 2007
Dave,

Ignore my last message.

After I first tried your code, I closed excel, reopened a workbook, and the
macro libraries (stored in XLS's in \XLSTART) were hidden as desired. Thanks!


"Allen_N" wrote:

> Nope. debugging reveals that ActiveWorkbook is Nothing.
>
> "Dave Peterson" wrote:
>
> > This may get you over the hump:
> >
> > Dim wkbk As Workbook
> > Dim myWindow As Window
> > Set wkbk = ActiveWorkbook
> > For Each myWindow In wkbk.Windows
> > myWindow.Visible = False
> > Next myWindow
> >
> >
> >
> > Allen_N wrote:
> > >
> > > Thanks, Bob.
> > >
> > > Now I'm trying:
> > >
> > > Windows(wb.Name).Visible = False
> > >
> > > but I still get "Object doesn't support this property or method".
> > >
> > > I confirmed that wb.Name = "PERSONAL.XLS".
> > >
> > > "Bob Flanagan" wrote:
> > >
> > > > Instead of wb.visible = false, you want to hide the window:
> > > >
> > > > Windows(ThisWorkbook.Name).Visible = False
> > > >
> > > > Bob Flanagan
> > > > Macro Systems
> > > > http://www.add-ins.com
> > > > Productivity add-ins and downloadable books on VB macros for Excel
> > > >
> > > >
> > > > "Allen_N" <(E-Mail Removed)> wrote in message
> > > > news:66A406C6-71B0-4D26-BD4C-(E-Mail Removed)...
> > > > > I'm trying to hide the workbook that contains my macro library. This used
> > > > > to
> > > > > work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> > > > > produces the error "Object doesn't support this property or method" and
> > > > > the
> > > > > error is not trapped.
> > > > >
> > > > > Sub auto_open()
> > > > >
> > > > > Dim i&, wb
> > > > >
> > > > > For i& = 1 To Workbooks.Count
> > > > > Set wb = Workbooks(i&)
> > > > > If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> > > > > If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> > > > > Next i&
> > > > >
> > > > > Exit Sub
> > > > >
> > > > > HideWB:
> > > > >
> > > > > On Error GoTo SkipHide
> > > > > wb.Visible = False
> > > > > SkipHide:
> > > > > On Error GoTo 0
> > > > > Return
> > > > >
> > > > > End Sub
> > > > >
> > > > > What could be going wrong?
> > > > >
> > > >
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Apr 2007
You'd still want to cycle through all the workbooks:

Option Explicit
Sub auto_open()

Dim i As Long
Dim wb As Workbook
Dim myWindow As Window

For i = 1 To Workbooks.Count
Set wb = Workbooks(i&)
If InStr(1, wb.Name, "personal.xls", vbTextCompare) > 0 _
Or InStr(1, wb.Name, "custom.xls", vbTextCompare) > 0 Then
For Each myWindow In wb.Windows
myWindow.Visible = False
Next myWindow
End If
Next i

End Sub


Allen_N wrote:
>
> Nope. debugging reveals that ActiveWorkbook is Nothing.
>
> "Dave Peterson" wrote:
>
> > This may get you over the hump:
> >
> > Dim wkbk As Workbook
> > Dim myWindow As Window
> > Set wkbk = ActiveWorkbook
> > For Each myWindow In wkbk.Windows
> > myWindow.Visible = False
> > Next myWindow
> >
> >
> >
> > Allen_N wrote:
> > >
> > > Thanks, Bob.
> > >
> > > Now I'm trying:
> > >
> > > Windows(wb.Name).Visible = False
> > >
> > > but I still get "Object doesn't support this property or method".
> > >
> > > I confirmed that wb.Name = "PERSONAL.XLS".
> > >
> > > "Bob Flanagan" wrote:
> > >
> > > > Instead of wb.visible = false, you want to hide the window:
> > > >
> > > > Windows(ThisWorkbook.Name).Visible = False
> > > >
> > > > Bob Flanagan
> > > > Macro Systems
> > > > http://www.add-ins.com
> > > > Productivity add-ins and downloadable books on VB macros for Excel
> > > >
> > > >
> > > > "Allen_N" <(E-Mail Removed)> wrote in message
> > > > news:66A406C6-71B0-4D26-BD4C-(E-Mail Removed)...
> > > > > I'm trying to hide the workbook that contains my macro library. This used
> > > > > to
> > > > > work, but has suddenly failed in 2 ways: the line "wb.Visible = False"
> > > > > produces the error "Object doesn't support this property or method" and
> > > > > the
> > > > > error is not trapped.
> > > > >
> > > > > Sub auto_open()
> > > > >
> > > > > Dim i&, wb
> > > > >
> > > > > For i& = 1 To Workbooks.Count
> > > > > Set wb = Workbooks(i&)
> > > > > If InStr(UCase$(wb.Name), "PERSONAL.XLS") Then GoSub HideWB
> > > > > If InStr(UCase$(wb.Name), "CUSTOM.XLS") Then GoSub HideWB
> > > > > Next i&
> > > > >
> > > > > Exit Sub
> > > > >
> > > > > HideWB:
> > > > >
> > > > > On Error GoTo SkipHide
> > > > > wb.Visible = False
> > > > > SkipHide:
> > > > > On Error GoTo 0
> > > > > Return
> > > > >
> > > > > End Sub
> > > > >
> > > > > What could be going wrong?
> > > > >
> > > >
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide all Sheets in Workbook then Close Workbook RyanH Microsoft Excel Programming 0 29th Jan 2008 12:59 PM
How do I trap errors when excel (not a workbook) launches =?Utf-8?B?UmljaGFyZFM=?= Microsoft Excel Programming 0 12th Jan 2006 11:01 AM
Trap SheetBeforeRightClick event from another workbook mp112849 Microsoft Excel Programming 2 15th Jun 2005 10:32 AM
How to trap delete row event and hide column event? Alan Microsoft Excel Programming 3 26th Apr 2005 04:25 PM
How to hide a workbook and to detect a hidden workbook in visual basic jn1971 Microsoft Excel Programming 0 5th May 2004 10:08 PM


Features
 

Advertising
 

Newsgroups
 


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