View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NicoB NicoB is offline
external usenet poster
 
Posts: 8
Default Open a password protected excel workbook from second workbook to fetch data using dynamic connection

I have done something like you with ADODB

In the Reference add : "Microsoft ActiveX Data Objects 2.5 Library
In your function of B add :
Dim cntXLSFile As ADODB.Connectio
Dim rstQuery As ADODB.Recordse
Dim strTmp As Strin

'sets the ODBC driver to read the Excel file (without opening it
Set cntXLSFile = New ADODB.Connectio
cntXLSFile.ConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=0;DBQ=" & [The Full File Name of A
'opens a connection to the Excel fil
cntXLSFile.Ope

'gets the marketing organisation, exercise year and report type from the FMRG templat
Set rstQuery = cntXLSFile.Execute("SELECT * FROM [The Named Range];"
If Not rstQuery is Nothing The
If Not rstQuery.EOF The
rstQuery.MoveFirs
strTmp = rstQuery.Fields("[The Field Name]").Valu
rstQuery.Clos
Set rstQuery = Nothin
End I
cntXLSFile.Clos
Set cntXLSFile = Nothin

To use it you must organize your data as follo
first row : list of the fields name (1 field by column [The Field Name]
and the data belo
A named range must be defined for the data including the field's name row ([The Named Range])

I hope this will help you
NicoB