View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
ward376 ward376 is offline
external usenet poster
 
Posts: 360
Default VBA Project to the Specific Computer

Gord is right - anything in an xl file can be had by someone if they
really want it.

I also didn't read your question thoroughly, or was thinking of
another question when I put together my posts...

You only want it to open on one computer? Regardless of user? You
can't keep it from opening, but you could tell it to close if the
computer name doesn't fit your criteria. If macros aren't enabled,
this won't help.

If your goal is to secure your code you should protect the project
with a password.

If your goal is to hide/protect the data in the workbook, you should
hide the sheets you don't want to be accessible (use veryhidden from
the properties of each sheet in the project explorer) but leave at
least one blank one (or one of your choice) visible. Excel requires
that at least one sheet be visible. Then you can use VBA to unhide the
sheets you want unhidden - either in the open event or manually. That
way, if the workbook is opened without enabling macros, the hidden
sheets stay hidden.

Any or all of these measures will only keep casual users out of your
data/code.

Private Sub Workbook_Open()
If Environ("computername") < "yourputer" Then
Me.Close
Else
Dim ws As Worksheet
For Each ws In Worksheets
ws.Visible = xlSheetVisible
Next ws
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name < "yoursheet" Then
ws.Visible = xlSheetVeryHidden
End If
Next ws
End Sub

Cliff Edwards