LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Error when save as CSV with VBA password protection on

I believe this is a bug in Excel 2003. I get an error when saving as
CSV with VBA password protection turned on. If I turn off password
protection, the same code runs without error.

To reproduce the problem...

1. Open a new Excel file.
2. Type "Test" in Sheet1 cell A1
3. using Excel's Control Toolbox toolbar, draw a button on the
worksheet
4. right click on the button and select "view code"
5. enter the following line of code in the button click event (be sure
to enter a path that exists on your system -- I used "c:\temp" which
did exist on my system):
ThisWorkbook.SaveAs "c:\temp\test.csv", xlCSVWindows
6. save your Excel file
7. click the button and observe that the VBA code runs without error
8. close the CSV file that you saved in step 7
9. re-open your Excel file that you saved in step 6
10. open the Visual Basic editor and select Tools\VBAProject Properties
from the menu
11. click the Protection tab, check the "Lock project for viewing"
checkbox, enter a password and click OK (this protects your VBA code).
12. close the Excel file
13. re-open the Excel file
14. click on the button you added in step 3 and notice the error.
"Run-time error '1004':
Method 'SaveAs' of object '_Workbook' failed
15. open the Visual Basic editor and attempt to view your code
16. when prompted for your password, enter it
17. click on the button you added in step 3 notice now the code runs
without error.

So it's clear that the same code runs fine when VBA password protection
is turned on or the password has been entered, or produces an error
when VBA password protection is turned off or the password has been
entered.

Any ideas how to correct this issue or work around it?

Thanks!

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Protection ElsiePOA Excel Discussion (Misc queries) 6 July 25th 06 05:25 AM
Prompt for protection password when not trying to access VBA Jamie B Excel Discussion (Misc queries) 0 July 13th 06 08:13 PM
Protect Workbook vs Worksheet?? Dan B Excel Worksheet Functions 3 November 7th 05 09:02 PM
How can I remove workbook protection with no password? Tony Excel Discussion (Misc queries) 1 October 19th 05 09:55 PM
Password protection andy Excel Discussion (Misc queries) 1 December 7th 04 02:51 PM


All times are GMT +1. The time now is 02:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"