Solved

Excel Connection to Other Encrypted Excel File

Posted on 2011-03-08
5
430 Views
Last Modified: 2012-05-11
Have one brand new document 1.xlsm.  Have one encrypted document 2.xlsx, which just has data in the upper left of 'Sheet1'.  From inside of 1.xlsm, would like to make a Data Connection to 2.xlsx, but when I try this if I click on the 'Test Connection' button, I get the message:

Microsoft Data Link Error: Test connection failed because of an error in initializing provider. External table is not in the expected format.

My intention is to add the data from 'Sheet1' of the encrypted 2.xlsx as a table on 'Sheet2' of 1.xlsm and then permanently hide Sheet2 in 1.xlsm.

The solution I am looking for is how to make the connection from within 1.xlsm to the encrypted 2.xlsx without getting an error message and without having to enter the password that is necessary to enter when just opening 2.xlsx.  If there is a way to include the password in the Connection String of the connection, that would be fine, or any other solution you could share would be great too.

I'm including the two sample files I've been testing with.

Also, I am using Microsoft Excel 2007.

Also, the password for 2.xlsx is 'test'.

Thank you so much for your time. 1.xlsm 2.xlsx
0
Comment
Question by:SEMCIT
  • 2
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35081278
To the best of my knowledge there is no way at all of doing that. You would have to open the file.
0
 
LVL 19

Expert Comment

by:akoster
ID: 35083763
Making a data connection to an encrypted file indeed is problematic.
A possible solution could be to open the file with a macro, automatically copy & paste the required data to your unencrypted excel file, and close the encrypted file again.

This can be performed without the user having to do anything,  althoug in this way the password used to open the encrypted file will be visible to anyone who knows how to open the vba editor.

A better option would be to ask the user for a password, and then use this to open the file.



0
 

Author Comment

by:SEMCIT
ID: 35085778
Thank you both for your guidance and thank you akoster for your possible solution.  Is there any chance you could share a simple example of how a macro would look to open the file that required a password?  Thanks again.
0
 
LVL 19

Accepted Solution

by:
akoster earned 500 total points
ID: 35096370
Sure !
Sub copy_from_protected_file()

Dim source_file As String, source_pwd As String, source_sheet As String, source_range As String, dest_cell As String
Dim source As Workbook
Dim dest As Range

source_file = "D:\temp\2.xlsx"
source_pwd = "test"
source_sheet = "Sheet1"
source_range = "A1:C4"
dest_cell = "B6"

'-- specify destination range
Set dest = ActiveSheet.Range(dest_cell)

'-- open encrypted file
Set source = Workbooks.Open(Filename:=source_file, Password:=source_pwd)

'-- copy source range
source.Worksheets(source_sheet).Range(source_range).Copy
Me.Paste Destination:=dest

'-- close encrypted file
source.Close False
Set source = Nothing

End Sub

Open in new window


paste this code in the sheet1 section of the vba editor and run it.
of course you'll have to update the source_* and dest_cell settings...
0
 

Author Closing Comment

by:SEMCIT
ID: 35097899
Thank you so much for letting me know that my original intent was not possible, but for offering me a workaround.  The sample you shared was even better than I expected.  Thanks again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now