Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Selection for Excel File

Status
Not open for further replies.

astonmak

MIS
Feb 14, 2003
41
0
0
CN
Dear all,

I'm intend to export data to excel file and disable the selection function on the worksheet, which is just in order to prevent users able to highlight the content and copy it to the other worksheet. And the code as following :

Set loApp = CreateObject("Excel.Application")
Set loExWB = loApp.Workbooks.Add
Set loExWS = loExWB.Worksheets(1)

loExWS.Cells(1, 1).Value = ...
loExWS.Cells(1, 2).Value = ...
...
With loExWS
.EnableSelection = xlNoSelection
.Protect Password:="abc", DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
End With
loApp.UserControl = True
loApp.Visible = True
Set loExWS = Nothing
Set loExWB = Nothing
Set loApp = Nothing

From the code, I already using loExWS.EnableSelection = xlNoSelection, but I still can highlight a range of cells in the worksheet, is it the real meaning of .EnableSelection.

Thanks alot
Aston
 
The Excel VBA help files say this about the EnableSelection method:

This property takes effect only when the worksheet is protected

And it gives this example:

With Worksheets(1)
.EnableSelection = xlNoSelection
.Protect Contents:=True, UserInterfaceOnly:=True
End With


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
That's already one of the part in my coding, but doesn't work,

PLEASE HELP!
PLEASE HELP!
PLEASE HELP!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top