473,396 Members | 1,898 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,396 software developers and data experts.

Autostore Password for Export from Access query to excel spreadsheet.

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
May 21 '07 #1
7 4927
ADezii
8,834 Expert 8TB
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.
May 22 '07 #2
I am exporting from a query in vba. I am not using transfer spreadsheet
May 24 '07 #3
ADezii
8,834 Expert 8TB
I am exporting from a query in vba. I am not using transfer spreadsheet
Post the code you are using to Export.
May 24 '07 #4
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.
May 25 '07 #5
ADezii
8,834 Expert 8TB
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.
May 26 '07 #6
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.
May 31 '07 #7
ADezii
8,834 Expert 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CreateMonthlyReport(rsschedulesrecords As DAO.Recordset, curday As String)
  2.  
  3. Dim excelapp As New Excel.Application
  4. Dim excelfile As New Excel.Workbook
  5. Dim excelsheet As New Excel.Worksheet
  6. Dim savefilepath As String
  7. Dim tempi As Integer
  8.  
  9. Set excelfile = excelapp.Workbooks.Open(CurrentProject.Path & "Template1.xls")
  10. Set excelsheet = excelfile.Worksheets.Item(1)
  11.  
  12. 'To UNPROTECT the Worksheet prior to writing data
  13. excelsheet.Unprotect Password:= "password in quotes"
  14.  
  15. excelsheet.Cells(4, 1) = "EFFECTIVE Fr:" & Format(txtStartDate, "mmmm-dd,YYYY") & _
  16. "To:" & Format(txtEndDate, "mmmm-dd,YYYY")
  17.  
  18. excelsheet.Cells(5, 7) = DateTime.Now
  19. excelsheet.Range("L13") = DateTime.Now
  20.  
  21. If Not (rsschedulesrecords.EOF) Then
  22.   tempi = 1
  23.     While Not rsschedulesrecords.EOF
  24.       excelsheet.Range("A9", "L9").Insert
  25.       excelsheet.Cells(9, 1) = tempi
  26.       excelsheet.Cells(9, 2) = Format(rsschedulesrecords.Fields(3).Value, "dd-mmm-yy")
  27.       excelsheet.Cells(9, 3) = Format(rsschedulesrecords.Fields(4).Value, "dd-mmm-yy")
  28.       excelsheet.Cells(9, 4) = curday
  29.       excelsheet.Cells(9, 5) = rsschedulesrecords.Fields(1).Value
  30.       excelsheet.Cells(9, 6) = rsschedulesrecords.Fields(2).Value
  31.       excelsheet.Cells(9, 7) = rsschedulesrecords.Fields(17).Value
  32.       excelsheet.Cells(9, 8) = rsschedulesrecords.Fields(20).Value
  33.       excelsheet.Cells(9, 9) = CStr(rsschedulesrecords.Fields(19).Value) & " - " & _
  34. CStr(rsschedulesrecords.Fields(22).Value)
  35.       excelsheet.Cells(9, 10) = rsschedulesrecords.Fields(23).Value
  36.       excelsheet.Cells(9, 11) = rsschedulesrecords.Fields(24).Value
  37.       excelsheet.Cells(9, 12) = rsschedulesrecords.Fields(28).Value
  38.       rsschedulesrecords.MoveNext
  39.          tempi = tempi + 1
  40.     Wend
  41. End If
  42.  
  43. 'To RE-PROTECT the Worksheet after writing data but before Save
  44. excelsheet.Protect Password:= "password in quotes"
  45.  
  46. savefilepath = "\" & curday & "_Report_On-" & CStr(Format(DateTime.Now, "dd_mmm_yyyy-hh_mm_ss")) & ".xls"
  47. excelfile.SaveAs CurrentProject.Path & savefilepath
  48.  
  49. excelapp.ActiveWorkbook.Close True, CurrentProject.Path & savefilepath
  50. excelapp.Quit
  51.  
  52. Set excelsheet = Nothing
  53. Set excelfile = Nothing
  54. Set excelapp = Nothing
  55.  
  56. End Sub
May 31 '07 #8

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

Similar topics

4
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...
4
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...
3
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...
3
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...
1
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 ...
3
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...
0
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...
1
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...
5
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
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
Oralloy
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,...
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
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...
0
tracyyun
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...
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,...

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.