I have a Macro which takes 45 seconds to complete. When the macro starts I want a Countdown timer to pop up like a message box which will countdown until Macro completion. I have searched but so far cant find any answers to this. Is this possible?
As #Thrum correctly mentioned in his comment this is not possible with a message box.
A MsgBox is modal and therefore blocks the entire Excel application. Nothing else can happen / be done while that message box window is open and waits for you to close it. Actually, you can even make message boxes system-wide modal. In that case no other Windows application will respond unless you close that little message box in Excel (check the option vbSystemModal within the VBA help regarding MsgBox).
However, with forms on the other hand you have a choice. You can make the form not modal.
UserForm1.Show (False)
In that case the code continues to run in the background while the form is shown to the user and permits the running VBA code to make changes to the form while it is shown to the user.
Related
I have a macro that extracts data from Microfocus RUMBA Mainframe Display and puts in Excel rows one after the other. I have created a Global Mainframe object and that is used for extraction to Excel. But when the process is running and if user decides to stop the processing he cannot click on Stop button on Excel or go to different tabs to see the data being pasted. He has to clicks like 6 times before tabs are switched or stopped.
I see that DoEvents allows mouse click events in the loop to do things but the code is written in a way that there is a lot of lines with in the loop and a function with no loop, and placing DoEvents after everyline seems irrational. I have a feeling there is a better to do that but not sure what that is. Can anyone please help?.
VBA is single threaded. So you can't have one VBA action interrupt another. If you had a cancel button, for example, and the user was allowed to click it via a DoEvents processing the cancel action would still run after the currently running procedure.
In Excel this single threaded nature ends up being a good thing because you generally don't want the user interacting with the workbook while you are making programmatic changes. If this was allowed you would get undefined behavior.
Your best course of action would be to make a .NET application that uses the Excel Interop extensions to move the data from the mainframe to Excel. If you use VB.NET then you will find the code is quite similar to VBA. In fact, the Excel.Application object model is identical so the macro code you already have ports cleanly over.
There is an add-in that will help RUMBA development here:
https://www.microfocus.com/documentation/rumba/desktop951/RumbaSystemAdminGuide/GUID-DDB7571D-6167-4F8B-876E-E7450F3030B2.html
My VBA application sometimes is shutdown because of Citrix time-out. And the normal close of the excel file is by clicking X button at the right upper corner.
My question is if VBA can judge the excel file is closed by which method. I need to do the further operations according to the method of closing the excel file. Thanks!
#HackSlash , the excel is put into Citrix environment, which will be time out after 15 minutes. if Citrix is time out, the excel file will be shutdown without saving the content. Some users of the VBA will click the button then go away; when they are back, the excel file is shutdown by Citrix without saving. After the user read through the result of VBA, they will clear the content for the sake of security. So here, the scenario is if the excel is shutdown by Citrix abnormally, I want to save the result of VBA, so that the user can still see the result after they go back; if the excel is closed by clicking X at the right-upper corner, it means that these users has read through the result, all the contents should be cleared for the sake of security. Thanks!
It depends on how Citrix is closing your Excel sessions (I am not familiar with it), but probably, Yes you can tell.
The trick is to catch the QueryClose event and then check the CloseMode parameter. A 0 means that it was closed by clicking the [X] on the windows control menu. Citrix is probably using reason 2 or 3.
However, be forewarned that Citrix may be killing the Excel process in such a way that that this event is not called (though other shutdown events may happen). You'll have to test it to be sure.
In Excel VBA, is it possible to change the window style of a shelled program?
Here's the situation in detail:
At the click of a command button, the user should be able to load a third-party scanning program. The software path and file are specified in a named cell called settings_scanningsoftware, as you can see below. However, I'm using the Shell program, which doesn't wait for the third-party software to load before continuing. If it did, my life would be easier. For that reason, I throw up a dialog box in Excel telling the user to wait for the software to load and then ready the item to be scanned before they click Ok. And, since I throw up a dialog box, I load the scanning program minimized so they can see the dialog box (instead of it being hidden behind the software window and they're wondering why nothing's happening). With me so far?
However, once they click Ok, I want Excel to give control to the scanning software and give it a regular-sized window. There's my problem: once the software is loaded minimized, I can't seem to change the window style to give it a regular window.
Here's my code:
On Error Resume Next
Dim ScannerShell As Integer
ScannerShell = Shell(Range("settings_scanningsoftware").Value, **vbMinimizedNoFocus**)
If (ScannerShell <> 0) Then
Dim MessageBoxValue As Integer
MessageBoxValue = MsgBox("When you're ready to scan the receipt, click Ok.", vbOKCancel, "Scan receipt")
If (MessageBoxValue = vbOK) Then
ScannerShell = Shell(Range("settings_scanningsoftware").Value, **vbNormal**)
AppActivate ScannerShell, False
SendKeys ("{TAB}{TAB}{TAB} ")
End If
End If
Notice I've got the vbMinimizedNoFocus bolded above so that the software loads minimized and the user can see the upcoming dialog box. Once they click Ok, though, the software's window should be normalized. But Excel won't do me that favour.
Is there a way to change the window style after it's loaded?
Never mind the SendKeys command. I put that in there to get the scanner to automatically scan once everything is in place (the key sequence is incomplete, but one problem at a time). I know SendKeys is not a great way of sending commands to a program, but I'll figure that out once I get this window style thing fixed.
Does anyone have any solutions for me? Thanks.
my original question posted
Simulate Double Click Event in IE EXCEL , VBA interaction
.
You said,
this is a deadlocks for me because 1) i trigger the prompt from excel
to retrieve data from server 2) the server is stop responding until
prompt is being dismissed 3) all codes coded to handle prompt not
being processed because excel still waiting for the #1 to complete
I made a tests with some suggestions in older threads, but nothing worked.
References of those older threads.
(1) Disable Alert message of a webpage using VBA code (Refer the second answer)
(2) vba to dismiss an IE8 or IE9 "message from webpage" popup window
The thing is that, VBA code execution get stops when IE display the Alert() message. As code execution is already stopped we are not able to handle the Alert() prompt using code. So user need to close the Alert() prompt manually which resumes the code execution.
For simplicity in testing, if you just try to create an IE object and display the prompt and put some other lines of code after the prompt than you will notice that execution of code get stopped when prompt get displayed and until you close the prompt manually further lines of code will not get execute.
I agree with the suggestion given by the Zhi Lv - MSFT in your referenced thread for using the Selenium Web driver.
It can be the easiest solution for this issue.
References:
(1) Selenium Web Driver
(2) Selenium handle alerts prompts confirmation popups
I have been building an IT Ticketing / inventory system, and the program is done, now I'm adding instructions for the end users and the other techs in our school. Since I know nobody will read an instruction manual, I opted to make instructions for each screen, and put them in Modal Windows, activated by pushing a Help button I added to the Screen Commands section.
That works wonderfully, so I decided to capture the KeyDown event, and launch the window if they press F1. This is where things get a little weird.
If the HelpWindow for this particular screen has been opened at least once, pressing F1 opens it again with no trouble. If it has never been opened, pressing F1 results in an Error 'Control 'HelpWindow' doesn't contain a modal window. OpenModalWindow/CloseModalWindow cannot be used.'
After closing this error message, F1 will launch the HelpWindow exactly as expected. Very bizarre...
Background information:
Visual Studio 2012
Lightswitch project in VB (I work in both VB and C#, flipped a coin for this project)
The Modal Window is a group on the screen that is not visible, named "HelpWindow"; I use OpenModalWindow("HelpWindow") to open it. The exact same line of code in the HelpButton_Execute code, and the event handler for the KeyDown event.
It's the same method I use for every other modal window in the program, for submitting new tickets, adding equipment to the inventory, etc.
This problem only happens in the event handler, and only the first time the F1 key is pressed. The behavior is the same on every screen that has a help window.
My attempts to Google the problem were fruitless. Has anybody ever seen this behavior before?
That does sound very strange. I have to admit that I haven't seen anything like this myself with a modal window.
You don't mention where you're trapping the KeyDown key, so it's a bit hard to comment on that.
What I have seen sometimes, especially when doing something a little "different", is the error message not telling you the actual cause of the problem.
I would try wrapping the code with a dispatcher call, to make sure the call is being performed on the correct thread, as well as a try/catch to see if you can find the real cause of the error:
Private Sub YourClickHandler
Try
Me.Details.Dispatcher.BeginInvoke(
Sub()
OpenModalWindow("HelpWindow")
End Sub)
Catch ex As Exception
Me.ShowMessageBox(ex.Message)
End Try
End Sub
I hope that helps, or at least points you in the direction of a solution.