473,471 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OutputTo MSExcel Password

benchpolo
142 New Member
I have a function the outputs file to MSExcel dynamically by date (ex. file_10292007.xls). How do I embed an MSExcel password in MSAccess VBA?
Oct 29 '07 #1
4 1896
Rabbit
12,516 Recognized Expert Moderator MVP
Just make sure you have add a reference to the Excel Objects library.
Expand|Select|Wrap|Line Numbers
  1. Function SetXLPW()
  2.     Dim appXL As Excel.Application
  3.     Dim wkbkXL As Workbook
  4.  
  5.     Set appXL = Excel.Application
  6.     Set wkbkXL = appXL.Workbooks.Open("C:\test.xls")
  7.  
  8.     With wkbkXL
  9.         .Password = "Test1"
  10.         .Save
  11.         .Close
  12.     End With
  13. End Function
  14.  
Oct 29 '07 #2
benchpolo
142 New Member
So, I output the file to excel then call this function to embed the password?
Oct 29 '07 #3
benchpolo
142 New Member
Since, these .xls files are dynamic will the code below work? Thanks.
Expand|Select|Wrap|Line Numbers
  1. Function SetXLPW()
  2.     Dim appXL As Excel.Application
  3.     Dim wkbkXL As Workbook
  4.  
  5.     Set appXL = Excel.Application
  6.     Set wkbkXL = appXL.Workbooks.Open("c:\temp\contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls")
  7.  
  8.     With wkbkXL
  9.         .Password = "Test1"
  10.         .Save
  11.         .Close
  12.     End With
  13. End Function
  14.  
Oct 29 '07 #4
Rabbit
12,516 Recognized Expert Moderator MVP
Since, these .xls files are dynamic will the code below work? Thanks.
Expand|Select|Wrap|Line Numbers
  1. Function SetXLPW()
  2.     Dim appXL As Excel.Application
  3.     Dim wkbkXL As Workbook
  4.  
  5.     Set appXL = Excel.Application
  6.     Set wkbkXL = appXL.Workbooks.Open("c:\temp\contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls")
  7.  
  8.     With wkbkXL
  9.         .Password = "Test1"
  10.         .Save
  11.         .Close
  12.     End With
  13. End Function
  14.  
You only need to put it in a separate function if you need to call it from multiple events. If you only need it in one place then you can inline it. That code won't work because the time will change. You'll have to store the filename in a temporary variable, before you create the file, and use it for both the creation of the file and when you open the workbook to set the password.
Oct 29 '07 #5

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

Similar topics

2
by: Randy Harris | last post by:
I'm using OutputTo to send data into Excel. It has been working nicely. Now, I need to add more worksheets using OutputTo. Whenever I use it, it replaces the existing worksheet. Is there any way...
1
by: paul.hanti | last post by:
This board has been a plethora of information. Thanks to all that respond! I have a quick question regarding the built-in OutputTo macro. I've built a shared database in Access 2003 (in Access...
4
by: deko | last post by:
When using OutputTo with a query, the 'File name' window in the 'Output To' dialog gets populated with the name of the query by default. This makes the exported file self-describing if the query...
2
by: fordesky | last post by:
Gday, I have a set of Access 2000 tables that I would like to export into a MS Word 2000 template at specific bookmark locations that I've set up. Would anyone know the code to achieve...
1
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. ...
5
by: sara | last post by:
I have reports that run from a form where the user can choose a date range, or they run automatically for a week in the "Weekly Reports" option. I created 2 queries and 2 reports - one query...
5
by: dancole42 | last post by:
I have a question regarding the DoCmd.OutputTo function. I have an invoice report that shows all of the invoices for a particular date. I want to create a button that will export each page of...
1
by: Simon | last post by:
Dear reader, With the DoCmd.OutputTo ...... you have the possibility to write a report to an external location. In case the external location is an existing file the DoCmd is not...
2
by: Jim Devenish | last post by:
I have a report which can be displayed on the screen with: DoCmd.OpenReport "RemittanceAdvice",acViewNormal,,"PaymentID = " & paymentRecID I now wish to create a snapshot of this, using the...
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...
1
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
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.