Hello,
I need to export the results of various queries to Excel. During the
export I would like to assign a read-only password and modify
password. I was using macros to export before and I am somewhat new
to VBA.
Please let me know of any additional needed information.
Thank you for the help in advance.
John
This is a shot in the dark. If you can record a macro in Excel to
apply the read-only and modify passwords, you can use the same VBA in
Access (with a reference to the Excel Object), except that you need to
make sure that the reference is like a fully qualified path rather
than like a relative path. E.g.,
The VBA Macro code to hide a row is:
Selection.EntireRow.Hidden = True
The VBA in Access required to perform the same operation becomes:
objXL.Selection.EntireRow.Hidden = True
where objXL was created with something like (for early binding):
Set objXL = CreateObject("Excel.Application")
and is followed by something like:
Set wbk = objXL.Workbooks.Open(strFileName)
objXL.Visible = True
where wbk is an Excel.Workbook object (when using Early Binding).
When I recorded a macro in A97 I got:
ActiveWorkbook.SaveAs FileName:= _
"C:\Documents and Settings\jimfortune\My Documents\Book2.xls",
FileFormat:= _
xlNormal, Password:="test1", WriteResPassword:="test2",
ReadOnlyRecommended _
:=False, CreateBackup:=False
so I suspect the equivalent VBA code in Access will look something
like (all one line):
objXL.ActiveWorkbook.SaveAs "C:\Documents and Settings\jimfortune\My
Documents\Book2.xls", -4143, "test1", "test2", False, False
Personally, I would do all this after transferring the data into the
spreadsheet
.
James A. Fortune
(e-mail address removed)
I remember thinking once, "Someday I'll have a 286 of my own, and then
won't life be grand."