Tags

Sub Test()
    Dim strFile As String
    strFile = Application.GetOpenFilename(“Excel workbooks,*.xls*”)
    ‘this gives a popo up browse option for user to select the excel file they want
    If strFile = “False” Then
        ‘ the user clicked Cancel
        ‘…
    Else
        Workbooks.Open strFile ‘now strfile is a variable declared above as string which stores the full path of the selected file by user
       

Dim Conn As New ADODB.Connection ‘creating variable for connection
Dim mrs As New ADODB.Recordset      ‘creating a recordset

Dim DBPath As String, sconnect As String

DBPath = strFile ‘DBpath stores the value from strFile
sconnect = “Provider=MSDASQL.1;DSN=Excel Files;DBQ=” & DBPath & “;HDR=Yes’;”

Conn.Open sconnect
sSQLSting = “SELECT  COUNT (*) From [General query for wlet error$] WHERE ACTVTST_CONDTN_CD IN (‘WACR01’)” ‘QL query to be fetched again your sheet

mrs.Open sSQLStingod, Conn
    ActiveSheet.Range(“AJ2”).CopyFromRecordset mrs ‘paste the recordseet values from the SQL query output
mrs.Close
Conn.Close
    End If
    End Sub