Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Searching a range in Closed Workbook

I have read, and read, and read, and I am still having problems

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

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Searching a range in Closed Workbook

Hi
though this is possible I'd suggest you open the other workbook
(disable screenupdating to prevent showing this to the user), do your
search and close the workbook again. should be faster than accessing a
closed workbook

--
Regards
Frank Kabel
Frankfurt, Germany

"TroyH" schrieb im Newsbeitrag
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Searching a range in Closed Workbook

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Searching a range in Closed Workbook

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





  #5   Report Post  
Posted to microsoft.public.excel.programming
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









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Searching a range in Closed Workbook

Before I forget. Thanks to everyone for helping out. It led me in the right direction.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help - Does value exist in range of CLOSED workbook? c mateland Excel Worksheet Functions 9 April 16th 07 06:53 PM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
Value from a closed workbook Anthony Slater Excel Discussion (Misc queries) 5 May 17th 05 09:49 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
VLookup error message while accessing range in closed workbook. Peter McNaughton Excel Programming 1 September 10th 03 06:11 AM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"