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 - Private Sub Command4_Click()
-
-
Dim db As DAO.Database, rs As DAO.Recordset, str1Sql As QueryDef, strCrt As String, strDt As String
-
Set db = CurrentDb
-
-
Set rs = db.OpenRecordset("SELECT distinct FundGroup FROM tbl_EFMMI_ReportFeeder ORDER By FundGroup;")
-
'**** fieldname, consider this to be how the records are grouped within the dataset.
-
-
strDt = [Forms]![Form1]![Period]
-
-
rs.MoveLast
-
rs.MoveFirst
-
-
Do While Not rs.EOF
-
-
strCrt = rs.Fields(0)
-
-
Set str1Sql = db.CreateQueryDef("" & strCrt, "SELECT tbl_EFMMI_ReportFeeder.* FROM tbl_EFMMI_ReportFeeder WHERE tbl_EFMMI_ReportFeeder.FundGroup = '" & strCrt & "';")
-
-
-
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "" & strCrt, "C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls", True
-
-
DoCmd.DeleteObject acQuery, "" & strCrt
-
-
rs.MoveNext
-
-
Loop
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
-
End Sub
1 9651
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). - Set a Reference to the Microsoft Excel XX.X Object Library
- In the General Declarations Section of your Form, Declare Object Variables to represent the Excel Application and an Excel Workbook.
-
Dim appExcel As Excel.Application
-
Dim wkb As Excel.Workbook
-
- 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.
- Set appExcel = New Excel.Application
- Execute the Code similar to that below:
- '****************************** Code intentionally omitted ******************************
-
-
Do While Not rs.EOF
-
-
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "" & _
-
strCrt, "C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls", True
-
-
Set wkb = appExcel.Workbooks.Open("C:\H\EFMMI\ " & strCrt & "_" & strDt & ".xls")
-
wkb.Password = "SECRET"
-
-
wkb.Save
-
wkb.Close
-
Loop
-
-
'****************************** Code intentionally omitted ******************************
-
-
appExcel.Quit
-
Set appExcel = Nothing
-
- When you Open any of these 40 Spreadsheets, you will have to supply the Password (SECRET).
- Good Luck, and let us know how you make out.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |