Hi All,
I have finally succeeded in exporting to a preformated excel spreadsheet.
I have one tiny setback.
One of the sheets I am exporting to must be password protected.
When I do this and export I am prompted for the password.
This defeats the point.
Is there a way in access to autostore the password for an excel spreadsheet so that everytime it is exported the password is automatically passed to excel.
Thanks in Advance
7 4927
Hi All,
I have finally succeeded in exporting to a preformated excel spreadsheet.
I have one tiny setback.
One of the sheets I am exporting to must be password protected.
When I do this and export I am prompted for the password.
This defeats the point.
Is there a way in access to autostore the password for an excel spreadsheet so that everytime it is exported the password is automatically passed to excel.
Thanks in Advance
Are you using the TransferSpreadsheet Method for your Export? If so, there is no built-in provision for passing the Worksheet Password in the process.
I am exporting from a query in vba. I am not using transfer spreadsheet
I am exporting from a query in vba. I am not using transfer spreadsheet
Post the code you are using to Export.
Here is the code below that I use to export to access.
Private Sub CreateMonthlyReport(rsschedulesrecords As DAO.Recordset, curday As String)
Dim excelapp As New Excel.Application
Dim excelfile As New Excel.Workbook
Dim excelsheet As New Excel.Worksheet
Dim savefilepath As String
Dim tempi As Integer
Set excelfile = excelapp.Workbooks.Open(CurrentProject.Path & "Template1.xls")
Set excelsheet = excelfile.Worksheets.Item(1)
excelsheet.Cells(4, 1) = "EFFECTIVE Fr:" & Format(txtStartDate, "mmmm-dd,YYYY") & _
"To:" & Format(txtEndDate, "mmmm-dd,YYYY")
excelsheet.Cells(5, 7) = DateTime.Now
excelsheet.Range("L13") = DateTime.Now
If Not (rsschedulesrecords.EOF) Then
tempi = 1
While Not rsschedulesrecords.EOF
excelsheet.Range("A9", "L9").Insert
excelsheet.Cells(9, 1) = tempi
excelsheet.Cells(9, 2) = Format(rsschedulesrecords.Fields(3).Value, "dd-mmm-yy")
excelsheet.Cells(9, 3) = Format(rsschedulesrecords.Fields(4).Value, "dd-mmm-yy")
excelsheet.Cells(9, 4) = curday
excelsheet.Cells(9, 5) = rsschedulesrecords.Fields(1).Value
excelsheet.Cells(9, 6) = rsschedulesrecords.Fields(2).Value
excelsheet.Cells(9, 7) = rsschedulesrecords.Fields(17).Value
excelsheet.Cells(9, 8) = rsschedulesrecords.Fields(20).Value
excelsheet.Cells(9, 9) = CStr(rsschedulesrecords.Fields(19).Value) & " - " & _
CStr(rsschedulesrecords.Fields(22).Value)
excelsheet.Cells(9, 10) = rsschedulesrecords.Fields(23).Value
excelsheet.Cells(9, 11) = rsschedulesrecords.Fields(24).Value
excelsheet.Cells(9, 12) = rsschedulesrecords.Fields(28).Value
rsschedulesrecords.MoveNext
tempi = tempi + 1
Wend
End If
savefilepath = "\" & curday & "_Report_On-" & CStr(Format(DateTime.Now, "dd_mmm_yyyy-hh_mm_ss")) & ".xls"
excelfile.SaveAs CurrentProject.Path & savefilepath
excelapp.ActiveWorkbook.Close True, CurrentProject.Path & savefilepath
excelapp.Quit
Set excelsheet = Nothing
Set excelfile = Nothing
Set excelapp = Nothing
End Sub
Here is the query I perform before exporting
Private Sub cmdExport_Click()
On Error GoTo FinalStep
Dim querystring As String
Dim dbase As DAO.Database
Dim rsSchedules As DAO.Recordset
Dim tempi As Integer
Dim rptcnt As Integer
rptcnt = 0
querystring = GetQueryString
If (Len(Trim(querystring)) > 0) Then
Set dbase = CurrentDb
If (Me.Optgroup.Value = OptMonthly.OptionValue) Then
MsgBox "Exporting monthly report for " & CStr(txtStartDate.Value) & _
" to " & CStr(txtEndDate.Value), vbExclamation, "Export"
tempi = 1
While tempi < 8
querystring = querystring & " AND " & GetWeekDay(tempi) & " = Yes "
Set rsSchedules = dbase.OpenRecordset(querystring)
If Not (rsSchedules.EOF = True) Then
CreateMonthlyReport rsSchedules, GetWeekDay(tempi)
rptcnt = rptcnt + 1
End If
rsSchedules.Close
tempi = tempi + 1
Wend
'I have ommitted some code here that applies to other reports
dbase.Close
If (rptcnt = 0) Then
MsgBox "No Repords Found for Excel Export", vbExclamation, "Export"
Else
MsgBox "Export to excel file(s) completed", vbExclamation, "Export Complete"
End If
Set rsSchedules = Nothing
Set dbase = Nothing
End If
I use the above code to export to excel. Initially Template1 was not password protected but when I password protected the template. I am prompted for a password right before MsgBox "Export To Excel completed" This defeats the point because I want the user to be able to export the information but only individuals with the password to open it.
Thanks helping.
Here is the code below that I use to export to access.
Private Sub CreateMonthlyReport(rsschedulesrecords As DAO.Recordset, curday As String)
Dim excelapp As New Excel.Application
Dim excelfile As New Excel.Workbook
Dim excelsheet As New Excel.Worksheet
Dim savefilepath As String
Dim tempi As Integer
Set excelfile = excelapp.Workbooks.Open(CurrentProject.Path & "Template1.xls")
Set excelsheet = excelfile.Worksheets.Item(1)
excelsheet.Cells(4, 1) = "EFFECTIVE Fr:" & Format(txtStartDate, "mmmm-dd,YYYY") & _
"To:" & Format(txtEndDate, "mmmm-dd,YYYY")
excelsheet.Cells(5, 7) = DateTime.Now
excelsheet.Range("L13") = DateTime.Now
If Not (rsschedulesrecords.EOF) Then
tempi = 1
While Not rsschedulesrecords.EOF
excelsheet.Range("A9", "L9").Insert
excelsheet.Cells(9, 1) = tempi
excelsheet.Cells(9, 2) = Format(rsschedulesrecords.Fields(3).Value, "dd-mmm-yy")
excelsheet.Cells(9, 3) = Format(rsschedulesrecords.Fields(4).Value, "dd-mmm-yy")
excelsheet.Cells(9, 4) = curday
excelsheet.Cells(9, 5) = rsschedulesrecords.Fields(1).Value
excelsheet.Cells(9, 6) = rsschedulesrecords.Fields(2).Value
excelsheet.Cells(9, 7) = rsschedulesrecords.Fields(17).Value
excelsheet.Cells(9, 8) = rsschedulesrecords.Fields(20).Value
excelsheet.Cells(9, 9) = CStr(rsschedulesrecords.Fields(19).Value) & " - " & _
CStr(rsschedulesrecords.Fields(22).Value)
excelsheet.Cells(9, 10) = rsschedulesrecords.Fields(23).Value
excelsheet.Cells(9, 11) = rsschedulesrecords.Fields(24).Value
excelsheet.Cells(9, 12) = rsschedulesrecords.Fields(28).Value
rsschedulesrecords.MoveNext
tempi = tempi + 1
Wend
End If
savefilepath = "\" & curday & "_Report_On-" & CStr(Format(DateTime.Now, "dd_mmm_yyyy-hh_mm_ss")) & ".xls"
excelfile.SaveAs CurrentProject.Path & savefilepath
excelapp.ActiveWorkbook.Close True, CurrentProject.Path & savefilepath
excelapp.Quit
Set excelsheet = Nothing
Set excelfile = Nothing
Set excelapp = Nothing
End Sub
Here is the query I perform before exporting
Private Sub cmdExport_Click()
On Error GoTo FinalStep
Dim querystring As String
Dim dbase As DAO.Database
Dim rsSchedules As DAO.Recordset
Dim tempi As Integer
Dim rptcnt As Integer
rptcnt = 0
querystring = GetQueryString
If (Len(Trim(querystring)) > 0) Then
Set dbase = CurrentDb
If (Me.Optgroup.Value = OptMonthly.OptionValue) Then
MsgBox "Exporting monthly report for " & CStr(txtStartDate.Value) & _
" to " & CStr(txtEndDate.Value), vbExclamation, "Export"
tempi = 1
While tempi < 8
querystring = querystring & " AND " & GetWeekDay(tempi) & " = Yes "
Set rsSchedules = dbase.OpenRecordset(querystring)
If Not (rsSchedules.EOF = True) Then
CreateMonthlyReport rsSchedules, GetWeekDay(tempi)
rptcnt = rptcnt + 1
End If
rsSchedules.Close
tempi = tempi + 1
Wend
'I have ommitted some code here that applies to other reports
dbase.Close
If (rptcnt = 0) Then
MsgBox "No Repords Found for Excel Export", vbExclamation, "Export"
Else
MsgBox "Export to excel file(s) completed", vbExclamation, "Export Complete"
End If
Set rsSchedules = Nothing
Set dbase = Nothing
End If
I use the above code to export to excel. Initially Template1 was not password protected but when I password protected the template. I am prompted for a password right before MsgBox "Export To Excel completed" This defeats the point because I want the user to be able to export the information but only individuals with the password to open it.
Thanks helping.
I am working on your dilemma, but as of yet have not come up with a viable solution. Be patient - I'll keep on trying.
I am working on your dilemma, but as of yet have not come up with a viable solution. Be patient - I'll keep on trying.
Thanks For Your Effort.
Thanks For Your Effort.
The answer is so simple that it actually eluded me but here you go. Insert lines 13 and 44 exactly where indicated in your code. Lines 12 and 43 are Comments and are not necessary, though it may be a good idea to keep them in place. Let me know how you make out. - Private Sub CreateMonthlyReport(rsschedulesrecords As DAO.Recordset, curday As String)
-
-
Dim excelapp As New Excel.Application
-
Dim excelfile As New Excel.Workbook
-
Dim excelsheet As New Excel.Worksheet
-
Dim savefilepath As String
-
Dim tempi As Integer
-
-
Set excelfile = excelapp.Workbooks.Open(CurrentProject.Path & "Template1.xls")
-
Set excelsheet = excelfile.Worksheets.Item(1)
-
-
'To UNPROTECT the Worksheet prior to writing data
-
excelsheet.Unprotect Password:= "password in quotes"
-
-
excelsheet.Cells(4, 1) = "EFFECTIVE Fr:" & Format(txtStartDate, "mmmm-dd,YYYY") & _
-
"To:" & Format(txtEndDate, "mmmm-dd,YYYY")
-
-
excelsheet.Cells(5, 7) = DateTime.Now
-
excelsheet.Range("L13") = DateTime.Now
-
-
If Not (rsschedulesrecords.EOF) Then
-
tempi = 1
-
While Not rsschedulesrecords.EOF
-
excelsheet.Range("A9", "L9").Insert
-
excelsheet.Cells(9, 1) = tempi
-
excelsheet.Cells(9, 2) = Format(rsschedulesrecords.Fields(3).Value, "dd-mmm-yy")
-
excelsheet.Cells(9, 3) = Format(rsschedulesrecords.Fields(4).Value, "dd-mmm-yy")
-
excelsheet.Cells(9, 4) = curday
-
excelsheet.Cells(9, 5) = rsschedulesrecords.Fields(1).Value
-
excelsheet.Cells(9, 6) = rsschedulesrecords.Fields(2).Value
-
excelsheet.Cells(9, 7) = rsschedulesrecords.Fields(17).Value
-
excelsheet.Cells(9, 8) = rsschedulesrecords.Fields(20).Value
-
excelsheet.Cells(9, 9) = CStr(rsschedulesrecords.Fields(19).Value) & " - " & _
-
CStr(rsschedulesrecords.Fields(22).Value)
-
excelsheet.Cells(9, 10) = rsschedulesrecords.Fields(23).Value
-
excelsheet.Cells(9, 11) = rsschedulesrecords.Fields(24).Value
-
excelsheet.Cells(9, 12) = rsschedulesrecords.Fields(28).Value
-
rsschedulesrecords.MoveNext
-
tempi = tempi + 1
-
Wend
-
End If
-
-
'To RE-PROTECT the Worksheet after writing data but before Save
-
excelsheet.Protect Password:= "password in quotes"
-
-
savefilepath = "\" & curday & "_Report_On-" & CStr(Format(DateTime.Now, "dd_mmm_yyyy-hh_mm_ss")) & ".xls"
-
excelfile.SaveAs CurrentProject.Path & savefilepath
-
-
excelapp.ActiveWorkbook.Close True, CurrentProject.Path & savefilepath
-
excelapp.Quit
-
-
Set excelsheet = Nothing
-
Set excelfile = Nothing
-
Set excelapp = Nothing
-
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paolo |
last post by:
Friends,
I need help with some code to export different tables to a single
spreadsheet in Excel.
My excel file is named REPORT and the spreadsheet is named CLIENTS.
I do have the code to export...
|
by: Gary Wright |
last post by:
I have an Access 2K database split into front and back. Quite often the
users want to do some data analysis that I have not created a report for so
they want to export some subset of the data into...
|
by: MissiMaths |
last post by:
I have used outputTo to export a copy of a table out of access into
excel. I was wondering if there is anyway to set a password on this
within the code so that it is read only in .xls format?
I...
|
by: John |
last post by:
Is there a way to code the button that's available in the query
window--microsoft excel icon that exports to excel. I know
transferspreadsheet will do this---but I want the query, which is in a...
|
by: Ellen Manning |
last post by:
I'm trying to export an Excel2K spreadsheet to A2K. Here is a sample
of the Excel spreadsheet:
LastName FirstName Hours Location HoursPercent
Doe John ...
|
by: excyauseme |
last post by:
Hi guys! Do you know what is the best way to export a text file, this
one is a log file that is already comma delimited thru a module run by
my access database, to an excel spreadsheet? I need to...
|
by: Simp33 |
last post by:
Is want to know is there anyway to attain the name of a table or the name of a query when you are exporting from access to excel. I want to be able to display the name of the access table/query that...
|
by: smaczylo |
last post by:
Hello, I've recently been asked to work with Microsoft Access, and
while I feel quite comfortable with Excel, I'm at a complete loss with
databases. If someone could help me with this issue I'm...
|
by: cdun2 |
last post by:
Hello,
I'm a non_VBA coder who has been asked to update the following Function:
**************************
Function EMAILER_REV_BY_ACCTCODE_MACRO()
On Error GoTo RA_EMAILER_Err
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |