Minimizable message box in VB - excel

I need a Visual Basic form that will allow the user to scroll through an Excel sheet while the form is running so that they can locate the information they need to enter into the form. Currently, the user must look up all the information before running the macro, which is obviously not very user friendly.
In other words, as the program is now, if the user tries to scroll through the Excel sheet (or do anything at all outside of the form), they are not allowed to without first canceling the form.
Is there a way to do this? Seems like this should be a simple thing to resolve, but I'm having trouble finding good VB documentation online.

Message boxes always pause the execution of the program. You'll need to find an alternative, for example by using the status bar instead, which is probably the easiest option. You can use the status bar in excel like this:
Application.StatusBar = "Hello world"
and
Application.StatusBar = variableName & " pounds."
and clear it using:
Application.StatusBar = False

Related

Out of stack space error when looping through forms with form.show and form.hide

I am writing a UserForm program in Excel which uses a number userforms in a non-linear fashion. The program is to be used to record animal sightings. I am getting an "Out of stack space" error.
The architecture is as follows; a Main Form opens, which is then hidden and the AnimalType1Home form is shown, this form asks you if you have seen any of these animals. If you answer YES, you are taken through a loop of 3 AnimalType1 forms which contain the details of the animal seen, after the loop you are returned to AnimalType1Home, where you can again answer YES and are taken through the loop again, and so on. If you answer NO, you are taken to AnimalType2Home, and the process continues through six or seven animal types, each with their own three details forms. There may be up to 25 of each animal.
I don't want to unload the forms because I am saving the information for each animal in string arrays (e.g. Dim size(1 to 25) as String). When I move from one form to the next, I hide the current form, and show the next:
me.hide
AnimalType1Home.show
me.hide
AnimalType1-1.show
me.hide
AnimalType1-2.show
me.hide
AnimalType1-3.show
me.hide
AnimalType1Home.show
etc.
Each of these hide/show lines are in different userforms, I hope I've explained that clearly. The problem I am getting is that if I try and enter over 15 or so animals, the program crashes with the "Out of stack space" error.
I have done a lot of Googling and I have found one very similar problem, and the answer has given me a clue as to the reason, but I'm not sure the original problem was actually solved and I'm not sure how to use this information:
https://www.mrexcel.com/board/threads/vba-userform-display-issue.349739/
The answer here seems to say not to put AnimalType1Home.show to return to the start of the form loop, but if I do that, then the AnimalType1Home form doesn't appear, which is what you might expect!
Edit: It seems that one solution would be to open some of the forms as Modeless, but I don't really like it, I don't want the spreadsheet to be editable while the forms are open and it seems like there must be another way.
Any help would be greatly appreciated.

How can I prevent user from doing anything else while Userform is displayed?

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.
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.
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...

Unprotecting VBA Editor Triggers Sub

I password protected my VBA Editor with:
Tools > VBAProject Properties > Protection
Clicked "Lock project for viewing"
Added a password.
What I need to have happen is that when this password prompt is accepted, It needs to run a Sub I've already written.
The answer I'm looking for and can't find in the three books on my desk is:
Is this action a Workbook Event? Or something else? And what syntax can make this happen.
Thanks!
Potential solution from MSDN:
https://msdn.microsoft.com/en-us/library/office/aa165442(v=office.10).aspx
This won't work for for what I'm trying to do. I wrote a script that asks for a key delivered weekly to authorized users via another program. What I wanted is a Sub to run which deletes all of my sensitive data if the user enters an incorrect password while attempting to get to the code.
Looks like this is not possible in Excel VBA... I'll keep learning and searching for a way to do this. If I do I will revisit this post.

Is it possible to launch the Scenario Manager using a VBA macro?

I am creating a MIS (Management Information System) in Excel, and am required to make use of 'What-If Analysis'.
I'm in the process of adding various scenarios to the Scenario Manager, and to make it more user-friendly I am displaying the whole system in full-screen. This however means that the user won't be able to open the Scenario Manager.
I cannot simply assign each scenario to a button/drop-down list as the user needs to have the ability to edit each scenario. This therefore means that I'll need to program a VBA macro to launch the Scenario Manager.
This, however, has presented a problem: it doesn't seem possible to launch the Scenario Manager using VBA!
I've tried searching for it, but however all pages I've visited contain code for launching an individual scenario with the following:
ActiveSheet.Scenarios("[scenario name here]").Show
However there doesn't seem to be anything to launch the actual scenario manager:
I've also attempted to record a macro to do this, but the macro itself is empty:
Sub whatIfManager()
'
' whatIfManager Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
End Sub
I tried ActiveSheet.Scenarios().Show on the off-chance that would work, but it doesn't (no method with that name).
Is it possible at all to launch the what-if scenario manager using VBA? If so, how?
The method you are looking for is in the Application object, specifically Application.Dialogs. Something like this will do it:
Application.Dialogs(xlDialogScenarioCells).Show
The enumeration value determines the dialog to show. The full list of dialogs is available here.

VBA-Explorer drop down menu selecting

I am a rookie to programming and am pretty sure that I am way over my head, but here is my problem. I work at a manufacturing facility that has a server that I do not have (and cannot have) access to. In order to retrieve and analyze data I have to go onto our Quality Management website which presents multiple drop down menus to select from. The first one is "Manufacturing date", then time, then machine ID, and then run the search. This then opens a new window that contains the data I need to insert into a previously written macro to organize. My buddy from work found this program:
Sub GoogleSearch()
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "http://mant6websrv1.thermatru.com/QMS/QualityReporting/Reports/LDMasterQueryReport.asp"
With objIE
.Visible = True
.navigate WebSite
Do While .Busy Or .readystate <> 4
DoEvents
Loop
Set Element = .document.getElementsByName("q")
Element.Item(0).Value = "Hello world"
.document.forms(0).submit
'.quit
End With
End Sub
It was originally a google search program that opens google in explorer and then searches the phrase "hello world". By simply replacing the website with our Quality Management address we have been able to get it to open the correct site, but I have no idea how to get it to select the options I want. I tinkered around a bit with the webdeveloper for explorer and even found the ID names for the boxes I need to fill out...but have no idea how to get the program to select them, and then insert the dates I want and run the search. Any ideas??
p.s. when I say I am a rookie I mean that this is my third day writing macros with vba so please be as simplistic and clear as possible with any answers. I am starting to really enjoy this stuff and want to learn as much as possible. Thanks everyone.
Try using the web macro recorder in Open Twebst. Record the actions you want to take and put the code in Excel's VB editor. In your case you can use VBScript, which can for the most part also be used with VBA. You might not get perfect result immediately with a recording, but it's a good tool to help you get on the right track, even if you may need to tinker with the code a bit and look through the HTML of the site to get perfect control.
Note however that it has its own framework for web automation, it's not recording using the standard Microsoft web libraries for it.

Resources