3

Like the title says, I have an Excel file with a macro running on load and I'd like to make it so the user can't use the computer while the macro is running.

It's a simple form for data input. However, most of the time users, just ignore it and let it run in the background while they work on other things.

Is it possible to make it so that while the Userform is being displayed, they can't do anything else on the computer forcing them to input the data?

I've tried everything from alerts to make them unable to close the form if they do not input data, but so far, nothing worked.

8
  • 4
    Show it modally. Commented Dec 4, 2018 at 15:04
  • 1
    learn.microsoft.com/en-us/office/vba/language/reference/… Commented Dec 4, 2018 at 15:04
  • 9
    Assuming it was possible, why would you want to prevent the user from doing anything? That's a horrible idea - you have no way of knowing if there are other uninterruptible processes running. If I ever opened an Excel file that did that, it would go straight to the recycle bin, because that's borderline malicious behavior. Commented Dec 4, 2018 at 15:11
  • 5
    If your application design is such that you must lock up the whole computer in order to work, then it's a sign that it's a design that you need to scrap though. Applications have been designed to work in a multi-tasking environments for decades. To emphasize this, the last time a Windows application could be system-wide modal was in... Windows 3.1. From 95 onward, it was no longer possible to do that and for a very good reason. Design your application to work gracefully in that environment instead of trying to hijack the OS. Commented Dec 4, 2018 at 15:21
  • 3
    @Barbaaz sounds like that's a management issue for The Workplace not a programming issue. If users refuse to properly do their job, they need a warning and a firing. Commented Dec 4, 2018 at 15:33

2 Answers 2

7

You can't do that. Your form is living in the EXCEL.EXE process space, and there is no way to tell Windows that EXCEL.EXE is all it's going to be doing until EXCEL.EXE says so.

This isn't a VBA limitation - you can't have a process that hijacks all message loops in every other processes on a machine, that's a recipe for disaster. I don't expect the OS to let you do that in any way, shape, or form.

Sign up to request clarification or add additional context in comments.

Comments

1

Inline with the above, its best practice not to irritate your users. However, if its an application on a machine with a sole function, i.e a visitor log then you could make the form a topmost form.

see for instance https://www.mrexcel.com/forum/excel-questions/386643-userform-always-top.html for an example, and https://www.jkp-ads.com/articles/apideclarations.asp for declarations of the windows API functions

Another approach is to set a timer and alert your user with a sound...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.