cannot run macro error on users laptop

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi and thanks for any help you can give.

I have a user who is getting the "cannot run the macro, the macro may not be available in the workbook" error.

I recently updated the workbook so only one user could access it according to their username so i'm assuming its this bit of code (which works fine on my own system).

I would really appreciate any help you can give me on this.

VBA Code:
Option Explicit
Option Private Module
Private Sub Users()

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False

Dim user As String
Dim Users(1) As String
Users(0) = "Mike"

user = Application.UserName
Dim access As Boolean
Dim i As Integer
access = False
For i = 0 To 0
    If Users(i) = user Then
        access = True
        Exit For
    End If
Next
If access = False Then
    MsgBox ("Sorry, the user """ & user & """ does not have the correct access rights to view this workbook")
    ActiveWorkbook.Close
End If

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I'm not sure what affect that would have. Give it a try. I'm curious now as well.
 
Upvote 0
I'm not sure what affect that would have. Give it a try. I'm curious now as well.
Cool beans, I'll keep you posted.

I just wanted to keep it off the list of macros so keeping it in a private module will do that for me. Making the sub public means i dont need to use application.run and can just use the standard "Call" so i'm hoping it makes the difference.
 
Upvote 0
Cool beans, I'll keep you posted.

I just wanted to keep it off the list of macros so keeping it in a private module will do that for me. Making the sub public means i dont need to use application.run and can just use the standard "Call" so i'm hoping it makes the difference.

where are you calling the code from?

Dave
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top