Avatar of Gary Croxford
Gary CroxfordFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Access VBA to Count Worksheets in a Workbook

Thank you for looking at my question,

I need to count the number of worksheets in an Excel workbook.

the code I have started with is:
        If intFileSelectedFlag > 0 Then
            Dim objXL As Object
            Dim objWB As Object
            Dim objWS As Object
            
            Set objXL = CreateObject("Excel.Application")
            Set objWB = objXL.workbooks.Open(strSource, True, True)
            Set objWS = objXL.worksheet
            
            For Each objWS In objWB.worksheets
                lngSheetCount = lngSheetCount + 1
            Next
            
            MsgBox "No. Sheets: " & lngSheetCount, vbOKOnly, "Source: " & strSource
        End If

Open in new window


The code falls over at "Set objWS = objXL.worksheet" with run-time error: 438 Object doesn't support this property or method"

How do I do this please?
VBAMicrosoft Access

Avatar of undefined
Last Comment
John Smith
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Gary Croxford
Gary Croxford
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thank you
Avatar of John Smith
John Smith

It works for me as well, great job!
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo