Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find the count of each users questions vbs script or excel macro

I need help with a script that can go to each page like this

I have the user names in a file or column A in excel

Then check the questions tab and get the count alone to column "B"

Please login to the site with these credentials to enter to the page

User name : EE-Test
Pass : EE-Test

Avatar of redmondb
Flag of Afghanistan image

Hi, bsharath.

Please see attached. The code is...
Option Explicit

Sub Check_URLS()
Dim i           As Long
Dim xResult     As Variant
Dim xCell       As Range
Dim xLast_Row   As Long

Sheets("Check URL's").Activate

xLast_Row = Range("A1").SpecialCells(xlLastCell).Row

If xLast_Row < 2 Then
    MsgBox ("No data found - run cancelled.")
    Exit Sub
End If

Range("B2:B" & xLast_Row).ClearContents

For Each xCell In Range("A2:A" & xLast_Row)
    If xCell <> "" Then
        i = i + 1
        xResult = Get_URL(xCell.Value)
        xResult = -1
    End If
    xCell.Offset(0, 1) = xResult
    Application.ScreenUpdating = True

End Sub

Function Get_URL(xUrl As String) As Variant
Dim xTempSheet  As Worksheet
Dim xConnection As String
Dim xFound      As Range

Application.ScreenUpdating = False

Set xTempSheet = Sheets.Add
xConnection = "x" & Format(Now(), "hhmmss")

On Error Resume Next

    With xTempSheet.QueryTables.Add(Connection:="URL;" & xUrl, Destination:=Range("$A$1"))
        .Name = xConnection
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingAll
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With

On Error GoTo 0

If xTempSheet.Range("A1").SpecialCells(xlLastCell).Row = 1 Then
    Application.DisplayAlerts = False
    Application.DisplayAlerts = True
    Get_URL = -1
    Exit Function
End If

Set xFound = xTempSheet.Range("A:A").Find(What:="No of Questions : ", LookIn:=xlFormulas, LookAt:=xlPart _
                , SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If xFound Is Nothing Then
    Get_URL = 0
    Get_URL = Mid(xFound, 19, 9999)
End If

Application.DisplayAlerts = False
Application.DisplayAlerts = True

End Function

Open in new window

Avatar of bsharath


Can i have the column with just the names

Mike Atherton

should be

I tried with this one name and i get 0 where as it has 6 questions

Sorry, I'm not clear about what you mean. Please post a sample entry

Edit: I tried "" and got 6 entries.

This URL

has 6 questions but excel shows as "0"

Yes, I got six as well. Did you use the same URL as I did or the Tinyurl?

Edit: Please post the file you used.

Please check attached file

That worked fine for me. I wonder is this possibly a log-in issue? To check this, please do the following...
 - On the Ribbon's menu bar, click on "Data".
 - On the Data tab, click on "From Web".
 - In the Address box, enter  "" (no quotes!) and xlixk on Import.

Do you get the user's details or a log-in prompt?

I get a login prompt
Thanks, bsharath, that explains our different results.

For the moment, use that log-in prompt to enter your user-id and password and then test the file. (The log-in should last until you restart Excel.) I'll look into passing the password.


There are a number of (insecure) ways of passing user-id and password in a URL, however I can't get them to work on Techyv. I don't know whether this is caused by my web ignorance or with the site itself.

Assuming that the code is otherwise OK, you may wish to raise a new question in a more appropriate topic here or directly in Techyv.

Please refer this

this code logs into the site. May be of help, not sure

Thanks for the interesting link. I dropped the code for creating a new question and my version successfully logs into Techyv. However, this doesn't make any difference in Excel - loading the page there still shows the user as logged off.

Consistently, if I have logged on from Excel (using "From Web") then the results are correct. However, once I've logged out from there then I get the zero results.

If it's not acceptable to you to do a manual log-on, I'd recommend that you suggest in one of your open questions in which Robert is involved that he get involved here. Not only could he give you the definitive answer on logging on, but he may also have a faster way of getting the data back.

Thanks Brian just left a note to Robert. Lets see if he can add help into this
ID: 38729850
As in this
can you run the excel and send back with the results please

Also i will be already logged in in IE before i run this macro

As in this
can you run the excel and send back with the results please.

Sorry, I don't understand this.

Also i will be already logged in in IE before i run this macro
That works with some sites, but, IIRC, not your one. Unfortunately the EE-Test login no longer works so I can't check this again.

please try password EE-test

What i meant was the above excel can you run the macro so i can see if the results are right

As for me all i get are 0's
Avatar of redmondb
Flag of Afghanistan image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, bsharath.