XL7: Count Method Returns Wrong Value If Shared Lists Active

ID: Q134682

The information in this article applies to:

SYMPTOMS

The Visual Basic, Applications Edition, Worksheets.Count method may return a value one larger than the actual number of worksheets contained in the workbook.

CAUSE

This problem occurs when the Shared Lists option is active. When the Shared Lists option is active, the book has had a special worksheet added that contains a list of all sharing conflicts and the resolution applied to these conflicts. This worksheet exists as long as the workbook is marked for sharing; it contains only the list of conflict resolutions.

WORKAROUND

To work around this problem, test to see if the workbook is shared before you count the worksheets. The following example sets a variable equal to the number of worksheets in the active workbook:

Sub Test()
   Dim X As Integer
   If ActiveWorkbook.MultiUserEditing = True Then
      X = Worksheets.Count - 1
   Else
      X = Worksheets.Count
   End If
   MsgBox ("The number of worksheets is " & X & ".")
End Sub

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

STATUS

Microsoft has confirmed this to be a problem in Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

If the Shared List option is active when you create a macro that uses the Worksheets.Count method, the macro will return a count of worksheets+1. This behavior may not be what you expect (you may expect a count of the worksheets only).

REFERENCES

Additional query words: 7.00

Keywords          : kbprg xlwin 
Version           : 7.00
Platform          : WINDOWS

Last Reviewed: September 3, 1997