L
Leslie Isaacs
Hello all
This is actually a continuation of a previous thread (subject "Transfer
text?") that I started on 12 Oct, but which has 'gone cold'. Essentially, I
need to export the results of a query to a password-protected excel
spreadsheet. One suggested solution was to use the
'ExportToPasswordedWorkbook' code below, so now I have that code in a
module, and I have
ExportToPasswordedWorkbook("C:\Documents and Settings\Administrator\My
Documents\nhsp_Joiner.xls","P0y3D0c","Query1")
as the OnClick event of a button, but when I click the button this results
in the compile error "Expected: ="
Does this mean that I have to specify some variable for the function's
output ... but then this isn't a 'function', it's a 'sub', which I thought
I understood to mean that it will simply perform an action (like setting an
object's property - or in this case exporting the query's output to the
spreadsheet) as opposed to computing a value that would need to be assigned
to a variable. Have I got this wrong?
I should add that I have a reference set to Microsoft Excel 9 Object
Library.
Hope someone can help.
Many thanks
Leslie Isaacs
The Sub code is:
Option Compare Database
Public Sub ExportToPasswordedWorkbook(strFile As String, _
strPassword As String, strQryName As String)
Dim oExcel As Excel.Application
Dim oWb As Excel.Workbook
Set oExcel = CreateObject("Excel.Application")
'Open protected workbook and remove password
Set oWb = oExcel.Workbooks.Open(FileName:=strFile, _
password:=strPassword)
oWb.password = ""
oWb.Close SaveChanges:=True
'Export
DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, strQryName, strFile, -1
'Restore password
Set oWb = oExcel.Workbooks.Open(FileName:=strFile)
oWb.password = strPassword
oWb.Close SaveChanges:=True
oExcel.Quit
Set oExcel = Nothing
End Sub
This is actually a continuation of a previous thread (subject "Transfer
text?") that I started on 12 Oct, but which has 'gone cold'. Essentially, I
need to export the results of a query to a password-protected excel
spreadsheet. One suggested solution was to use the
'ExportToPasswordedWorkbook' code below, so now I have that code in a
module, and I have
ExportToPasswordedWorkbook("C:\Documents and Settings\Administrator\My
Documents\nhsp_Joiner.xls","P0y3D0c","Query1")
as the OnClick event of a button, but when I click the button this results
in the compile error "Expected: ="
Does this mean that I have to specify some variable for the function's
output ... but then this isn't a 'function', it's a 'sub', which I thought
I understood to mean that it will simply perform an action (like setting an
object's property - or in this case exporting the query's output to the
spreadsheet) as opposed to computing a value that would need to be assigned
to a variable. Have I got this wrong?
I should add that I have a reference set to Microsoft Excel 9 Object
Library.
Hope someone can help.
Many thanks
Leslie Isaacs
The Sub code is:
Option Compare Database
Public Sub ExportToPasswordedWorkbook(strFile As String, _
strPassword As String, strQryName As String)
Dim oExcel As Excel.Application
Dim oWb As Excel.Workbook
Set oExcel = CreateObject("Excel.Application")
'Open protected workbook and remove password
Set oWb = oExcel.Workbooks.Open(FileName:=strFile, _
password:=strPassword)
oWb.password = ""
oWb.Close SaveChanges:=True
'Export
DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, strQryName, strFile, -1
'Restore password
Set oWb = oExcel.Workbooks.Open(FileName:=strFile)
oWb.password = strPassword
oWb.Close SaveChanges:=True
oExcel.Quit
Set oExcel = Nothing
End Sub