473,413 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Adding password to exported excel files from access

4
I have a table of data that i export into individual files from a grouped field, so creating 40 files each named as the group filed with a period in the names. I would like a process that will add a password to each of these exported files, can anyone help please. this is the code i use to export the files

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command4_Click()
  2.  
  3.   Dim db As DAO.Database, rs As DAO.Recordset, str1Sql As QueryDef, strCrt As String, strDt As String
  4.   Set db = CurrentDb
  5.  
  6.   Set rs = db.OpenRecordset("SELECT distinct FundGroup FROM tbl_EFMMI_ReportFeeder ORDER By FundGroup;")
  7.   '**** fieldname, consider this to be how the records are grouped within the dataset.
  8.  
  9.   strDt = [Forms]![Form1]![Period]
  10.  
  11.   rs.MoveLast
  12.   rs.MoveFirst
  13.  
  14.   Do While Not rs.EOF
  15.  
  16.   strCrt = rs.Fields(0)
  17.  
  18.   Set str1Sql = db.CreateQueryDef("" & strCrt, "SELECT tbl_EFMMI_ReportFeeder.*  FROM tbl_EFMMI_ReportFeeder WHERE tbl_EFMMI_ReportFeeder.FundGroup = '" & strCrt & "';")
  19.  
  20.  
  21.   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "" & strCrt, "C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls", True
  22.  
  23.   DoCmd.DeleteObject acQuery, "" & strCrt
  24.  
  25.   rs.MoveNext
  26.  
  27.   Loop
  28.  
  29.   rs.Close
  30.   Set rs = Nothing
  31.   Set db = Nothing
  32.  
  33.  
  34. End Sub
Oct 25 '11 #1
1 9651
ADezii
8,834 Expert 8TB
After each Query is Exported via the TransferSpreadsheet() Method, using Automation Code, Open the Exported Spreadsheet in Excel, and Set the Password for the Workbook to 'SECRET'. Save each Workbook, then Close it. Repeat for each iteration of the Loop. This works well for a single Workbook, but on 40, you'll have to provide the answer to that one! (LOL).
  1. Set a Reference to the Microsoft Excel XX.X Object Library
  2. In the General Declarations Section of your Form, Declare Object Variables to represent the Excel Application and an Excel Workbook.
    Expand|Select|Wrap|Line Numbers
    1. Dim appExcel As Excel.Application
    2. Dim wkb As Excel.Workbook
    3.  
  3. In the Form's Open() Event, create an Instance of the Excel Application. The idea here is to create a 'Single' Instance and work with it as opposed to Multiple Instances.
    Expand|Select|Wrap|Line Numbers
    1. Set appExcel = New Excel.Application
  4. Execute the Code similar to that below:
    Expand|Select|Wrap|Line Numbers
    1. '****************************** Code intentionally omitted ******************************
    2.  
    3. Do While Not rs.EOF
    4.  
    5.   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "" & _
    6.                             strCrt, "C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls", True
    7.  
    8.   Set wkb = appExcel.Workbooks.Open("C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls")
    9.       wkb.Password = "SECRET"
    10.  
    11.       wkb.Save
    12.       wkb.Close
    13. Loop
    14.  
    15. '****************************** Code intentionally omitted ******************************
    16.  
    17. appExcel.Quit
    18. Set appExcel = Nothing
    19.  
  5. When you Open any of these 40 Spreadsheets, you will have to supply the Password (SECRET).
  6. Good Luck, and let us know how you make out.
Oct 25 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Geert-Pieter Hof | last post by:
Hello, My VB 6.0 application read and writes data from and to a MS Excel workbook, using the Microsoft.Jet.OLEDB.4.0 provider. Now I want to protect the Excel workbook with a password, but I...
0
by: Chris Powell | last post by:
I am using Excel/Access 2000 and have two large Excel files (25,000 rows each) that I wish to create linked tables in Access rather than importing into Access. The two source Excel files change...
0
by: Oci-One Kanubi | last post by:
Everything works fine in Access, but when I double-click on the resultant Excel files the first one opens correctly, but subsequent ones, and any other Excel files I try to open, fail to display at...
0
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
3
by: | last post by:
I am writing a small program that needs to be able to open Excel workbooks which are password protected. Does anyone know how to do this, without any interaction from the user? I am sure it is...
2
by: amy | last post by:
Hi, all: i am a new end user of access, now I have many excel files need to import to One table in access (combine all excel files into one table in excel). In excel files, some columns will have...
0
by: amy | last post by:
Hi, all: > i am a new end user of access, now I have many excel files need to > import to One table in access (combine all excel files into one table > in excel). In excel files, some columns will...
11
by: MD | last post by:
Hello, I need to import a sheet of 884 different excel-file with same lay- out. The sheet name is 'Totaal' and is the same in all different files. Is there a script (module) in order to: 1....
28
by: kkadakia | last post by:
I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to...
1
by: mohanprasadgutta | last post by:
Hi, I need help to open a password protected excel file in perl using Win32:OLE. when I tried to open file in normal way at the time of program execution it is prompting me to enter password. I am...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.