Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Extracting Data Without Opening Workbooks

Hello!

I have these below given codes that extract data from Excel files without
opening those files. The problem is if those files are password protected
these codes do not work. I tried to fit in the Password:=fsgsg(example)
but no use.
Could someone help?
Thanks.

Sub AccessingExcel()

Dim recordset As ADODB.recordset
Dim SQL As String
Dim connectionstring As String

connectionstring = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & "Book1" & ".xls; " & _
"Extended Properties=Excel 8.0;"

SQL = _
"select * from (B1:B50000)"

Set recordset = New ADODB.recordset

recordset.Open SQL, connectionstring

Cells(1, 1) = recordset.Fields(0)

recordset.Close

End sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Extracting Data Without Opening Workbooks

I can't help with that approach but you can extract data from closed workbbok
using formula which I think, is not affected by password problems (although
could be wrong!)

something like following may work for you:



Sub GetData()
Dim mydata As String
'data location & range to copy
mydata = "='C:\[mybook.xls]Sheet1'!$B$2:F12" '<< change as required

'link to worksheet
With ThisWorkbook.Worksheets(1).Range("B2:F12") '<< change as required
.Formula = mydata

'convert formula to text
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
End Sub

just an idea, sorry if of no help.
--
jb


"Varne" wrote:

Hello!

I have these below given codes that extract data from Excel files without
opening those files. The problem is if those files are password protected
these codes do not work. I tried to fit in the Password:=fsgsg(example)
but no use.
Could someone help?
Thanks.

Sub AccessingExcel()

Dim recordset As ADODB.recordset
Dim SQL As String
Dim connectionstring As String

connectionstring = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & "Book1" & ".xls; " & _
"Extended Properties=Excel 8.0;"

SQL = _
"select * from (B1:B50000)"

Set recordset = New ADODB.recordset

recordset.Open SQL, connectionstring

Cells(1, 1) = recordset.Fields(0)

recordset.Close

End sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Extracting Data Without Opening Workbooks


I hope it's not too late to join the party...

Take a look at this:
http://www.rondebruin.nl/ado.htm

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"john" wrote:

I can't help with that approach but you can extract data from closed workbbok
using formula which I think, is not affected by password problems (although
could be wrong!)

something like following may work for you:



Sub GetData()
Dim mydata As String
'data location & range to copy
mydata = "='C:\[mybook.xls]Sheet1'!$B$2:F12" '<< change as required

'link to worksheet
With ThisWorkbook.Worksheets(1).Range("B2:F12") '<< change as required
.Formula = mydata

'convert formula to text
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
End Sub

just an idea, sorry if of no help.
--
jb


"Varne" wrote:

Hello!

I have these below given codes that extract data from Excel files without
opening those files. The problem is if those files are password protected
these codes do not work. I tried to fit in the Password:=fsgsg(example)
but no use.
Could someone help?
Thanks.

Sub AccessingExcel()

Dim recordset As ADODB.recordset
Dim SQL As String
Dim connectionstring As String

connectionstring = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & "Book1" & ".xls; " & _
"Extended Properties=Excel 8.0;"

SQL = _
"select * from (B1:B50000)"

Set recordset = New ADODB.recordset

recordset.Open SQL, connectionstring

Cells(1, 1) = recordset.Fields(0)

recordset.Close

End sub

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
Extracting data from multiple new workbooks via one master workboo iBob Setting up and Configuration of Excel 1 March 2nd 10 08:06 AM
Extracting data from multiple new workbooks via one master workboo iBob Excel Worksheet Functions 1 January 15th 10 04:21 AM
etract unique data from multiple workbooks after extracting data [email protected] Excel Programming 3 December 27th 07 06:56 AM
Reading Data from workbooks without opening them ... RFraley[_2_] Excel Programming 1 September 24th 06 11:16 PM
Copy data from diff workbooks but without opening sheets raja Excel Programming 1 September 21st 05 02:21 PM


All times are GMT +1. The time now is 03:07 AM.

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"