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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Candyman8019

Board Regular
Joined
Dec 2, 2020
Messages
138
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

I'm not sure what affect that would have. Give it a try. I'm curious now as well.
 

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
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.
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,521
Office Version
  1. 2019
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,118
Messages
5,640,216
Members
417,131
Latest member
Seanr19871

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
Top