View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Searching a range in Closed Workbook

Me too Ron,

That and FSO and APIs.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Ron de Bruin" wrote in message
...
Hi Bob

I have add a page with some examples last week to my site that use ADO.
http://www.rondebruin.nl/ado.htm

I like it this ADO stuff


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Bob Phillips" wrote in message

...
Troy,

here is one way

Public Sub Query()
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim sFile As String
Dim oOrig As Worksheet
Dim osh As Worksheet
Dim oCell As Range

sFile = "C:\myTest\volker1.xls"

' Create the connection string.
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFile & ";" & _
"Extended Properties=Excel 8.0;"

' Query based on the worksheet name.
sSQL = "SELECT * FROM [Sheet1$]"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, 0, 1, 1

' Check to make sure we received data.
If Not oRS.EOF Then
Application.ScreenUpdating = False
Set oOrig = ActiveWorkbook.ActiveSheet
Worksheets.Add.Name = "_temp"
Set osh = ActiveSheet
osh.Range("A1").CopyFromRecordset oRS
On Error Resume Next
Set oCell = osh.Cells.Find("POOLE")
If oCell Is Nothing Then
MsgBox "Not Found"
Else
MsgBox "Found"
End If
oOrig.Activate
Application.DisplayAlerts = False
osh.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
On Error GoTo 0
Else
MsgBox "No records returned.", vbCritical
End If

' Clean up our Recordset object.
oRS.Close
Set oRS = Nothing

End Sub




--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"TroyH" wrote in message
...
I have read, and read, and read, and I am still having problems.

I have two workbooks, PA.xls and PA_DB.xls

I would like to press a button on PA.xls and do a search in PA_DB.xls

within VBA.

PA_DB.xls has only one sheet, Database. The Range is MRN_Data.

If anyone can help me I would be forever grateful. I have spent way to

much time on this one.

Thanks