LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Protecting VBA (Excel) code

Peter, you're a star. Thank you. It's so obvious now! And yes, I
will work on those selects - although in my defence I do find them
useful when debugging because I can see that I've gone to the right
cell...!!

Cheers

Malc




On 1 Feb, 17:01, "Peter T" <peter_t@discussions wrote:
Looks like you are trying to save the workbook with the locked code as a
textfile, indeed that fails for me too.

If you just want to save a sheet as a text file do something like this
(aircode)

activesheet.copy
activeworkbook.saveas ' blah
activeworkbook.close

In effect copy the sheet to a new single sheet workbook, saveas, then close
it.

In passing, try and remove all those Selects none of which are necessary if
you reference the ranges correctly.

Regards,
Peter T

"Malc" wrote in message

...



Guys - thanks for your help, but having taken your advice I still have
the problem.
I took out the error handler because I wanted to see what the error
actually was. *I had displayalerts set to false because the file I'm
creating might or might not exist and with it set like this I don't
get the overwrite? message.
I'm still mystified why code that works perfectly well as long as it
isn't protected stops working as soon as it is!
Anyway, as there's a suggestion that the problem isn't in my code,
maybe you'd like to see all of it. *I should say that I'm not a
programmer and I've picked up what I know, so please don't laugh too
much at my efforts!
I also noticed that even with the project unlocked and the alerts
turned on I could overwrite the file OK but if I Cancelled or said No
I'd get the failure message.


Thanks again:


* * Dim DSNDirectory As String
* * Dim DSNFilename As String
* * Dim FileSaveDirectory As String
* * Dim FileSaveName As String
* * Dim PWEntry As String
* * Worksheets("Setup").Activate
* * Range("pwdentry").Select
* * If ActiveCell.Formula = "********" Then
* * * * Range("pwdentry").ClearContents
* * End If
* * Range("pwdentry").Select
* * If ActiveCell.Formula = "" Then
* * PWEntry = InputBox("Enter SunSystems Password")
* * Range("pwdentry") = PWEntry
* * 'Exit Sub
* * End If
* * Range("pwdentry").Copy
* * Range("pwd").Select
* * ActiveSheet.Paste
* * *Selection.NumberFormat = ";;;"
* * With Selection.Interior
* * * * .ColorIndex = 34
* * * * .Pattern = xlSolid
* * End With
* * Range("pwdentry").Select
* * ActiveCell.Formula = "********"
* * Range("appserver").Select


* * DSNDirectory = "\\" & Range("appserver") & "\" &
Range("appprogdir") & "\utils\"
* * DSNFilename = Range("dsnfile")


* * FileSaveDirectory = Range("FileSaveDirectory")
* * FileSaveName = Range("FileSavename")


* * Worksheets("DSN").Activate
* * Worksheets("DSN").Calculate


* * Application.DisplayAlerts = True
* * 'Application.DisplayAlerts = False


****ERROR OCCURS HERE IF PROJECT IS LOCKED****
* * * * ActiveWorkbook.SaveAs Filename:=DSNDirectory & DSNFilename, _
* * * * FileFormat:=xlTextMSDOS, CreateBackup:=False
* * Application.DisplayAlerts = True- Hide quoted text -


- Show quoted text -




 
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
Protecting Code in Visual Basic Editor (Excel 2003) Johnny S. NH Excel Worksheet Functions 1 August 30th 08 07:26 AM
Protecting VB Code Sanjay[_2_] Excel Programming 1 April 20th 07 05:32 PM
Protecting the code Harald Staff Excel Programming 0 August 31st 04 02:58 PM
Protecting buttons with VB code rather than protecting sheets/books? StargateFanFromWork Excel Programming 2 July 16th 04 04:03 PM
Hiding/Protecting vb code in excel IanStrange Excel Programming 1 November 10th 03 10:37 AM


All times are GMT +1. The time now is 08:53 AM.

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"