VBA Project to the Specific Computer

S

Shazi

Hi,

I made a vba project, I want to use this only in office pc. my
username is shahzadz and my computer name is medhihi0138, is there any
way, to assign vba file to the specific pc, I mean it should be open
only one computer, if any one try to open this file in other pc, it
should not open.

any suggession,pls reply me.

regards.

Shahzad
 
B

Barb Reinhardt

As I posted my response, I realized one fatal flaw in your logic. What
happens when you get a new computer and the computer name is different? You
won't even be able to open your own workbook.
 
S

Shazi

As I posted my response, I realized one fatal flaw in your logic.   What
happens when you get a new computer and the computer name is different?  You
won't even be able to open your own workbook.
--
HTH,
Barb Reinhardt







- Show quoted text -

Hi Mr. Barb Reinhardt,

I will open my project with disabled macros. and then I will remove
restriction or change according to new computer. then I will open in
other pc.

Anyway, I need this function to prevent my programs run other pc.,
some peoples are theef, they can stol my programs and they have all my
passwords, because they are working on my pc.

Regards.

shahzad
 
W

ward376

If Environ("username") <> "me" And Environ("computername") <>
"myputer" Then Exit Sub

Cliff Edwards
 
S

Shazi

If Environ("username") <> "me" And Environ("computername") <>
"myputer" Then Exit Sub

Cliff Edwards

Hi, Cliff Edwards,

I would appreciate, if you could explain how to use your code, I mean
which place and what is the full procedure will be.....

can I use this in Auto_Open macro or where ....

Regards.

Shahzad
 
B

Barb Reinhardt

The only way people can get to my files is to log on to my computer with my
user name and password. I'd suggest you improve the security on your
computer.

FYI, I'm not and never will be a Mr. ;)
 
W

ward376

Sorry Shazi, I should have been more thorough - put the code in the
workbook module (ThisWorkbook) and use the open event to trip it.

I also changed to a block style if so you can put your code in.

Private Sub Workbook_Open()

If Environ("username") <> "shahzadz" And _
Environ("computername") <> "medhihi0138" _
Then
Exit Sub
Else
'do your stuff
End If

End Sub

You'll want to verify your environ("username") also -
sub check()
msgbox environ("username")
end sub

You may want to use application.username instead
sub check()
msgbox application.username
end sub

Just preference on your part on whether to use your environ or
application username.

Cliff Edwards
 
W

ward376

Just thinking - you should use the logic that if your username and
computername are correct, run your code, rather than if both your
username and computername aren't correct, then don't run your code.

Private Sub Workbook_Open()

If Environ("username") = "shahzadz" And _
Environ("computername") = "medhihi0138" _
Then
'do your stuff
Else
Exit Sub
End If

End Sub

Cliff Edwards
 
G

Gord Dibben

You created a VBA project in a workbook on your computer and you don't want
someone to steal your code from this workbook.........right?

Don't distribute the workbook.

Or use encryption to secure the workbook from being opened by anyone else.

If you want others to be able to use the workbook, there is no way you can
prevent them from stealing your code.

You can lock the project for viewing but a good hex editor or password
cracker can bypass that.


Gord Dibben MS Excel MVP
 
W

ward376

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top