I'm a new VBA user. I have a workbook with multiple worksheets. Each one has it own userform for data entry. The userform shows when I click on the sheet. After I'm done entering data, the worksheet is populated and the userform closes (unload). All this works well. However, after the initial data entry is complete, the goal is to use the data on the worksheets for other applications and the userform is no longer needed. What is the code or the terminology to say the userform should not reappear again when the worksheet is clicked on? Currently, I red X out of the userform. If I click the command button to close, it repopulates and I lose all my data.
Thanks!
As A.S.H commented; you could store the information in a number of ways. An easy example is declaring a variable outside of the Macro:
Public FormOpened as boolean
And then set FormOpened as true once the form has been shown. Then you could add a check to the start of the mouse-click macro:
If FormOpened = True then Exit sub
Related
How do I keep the values that where inputted into the excel Userform from clearing itself out once I click on the finish button? So whenever I call upon the Userform through a Commandbutton the previously filled field information is left the way it is and not to be cleared basically.
This Userform consist of MultiPage which is designed to take in the inputs from the user and place them in excel cells once the user has hit the finish button. Within the Userform contains Commandbuttons which toggles an hide/unhide feature which will also have to be saved somewhere
The Finish page (where the user will close/exit the page) looks like this:
Code for the finish button so far:
I'm not sure why everyone is saying there is no way to do this - you should be able to use:
Private Sub BtnFinish_Click()
Me.Hide
End Sub
And all previous values will be kept. Someone correct me if I'm wrong :).
I should add that once the EXCEL.EXE is closed, the values are lost.
I have a code which processes an excel sheet row by row.
Under certain conditions, certain manual manipulations are to be done on the data in the rows. For this, the program fires a UserForm. The UserForm contains certain fields which are populated from the underlying excel rows. These fields are then manipulated by the user and certain buttons on the userform are clicked. Once the manual processing is done, the program then needs to proceed with the rest of the rows in the Excel sheet. When the UserForm is triggered, before taking action on the USERFORM, user needs to to see
a) What is pushed up in the UserForm
b) Contents of the Underlying Excel Sheet
The program needs to wait till the user takes action
However, there seems to be no easy way to let the user see the underlying rows as the Userform (on top) prevents access to the Excel Sheet below. To allow access to the Excel Worksheets, I tried using
UserForm.Show vbModeless
UserForm.Show False
Both of these are totally bypassing the Userform and the program runs for the remaining rows without waiting for the user input.
I researched here and found this.
deactivate Excel VBA userform
In my Case, the MainProgram calls the UserForm and has to wait for the user input in the USERFORM before processing further rows. If the conditions triggering the userform are not met, the program proceeds to the next rows.
Help highly appreciated. Thanks in advance.
EDIT:
As a workaround I have written a line to select the cell where the manual intervention is triggered. This brings that cell right under the manual intervention UserForm. The UserForm can now be moved around to look at what is below.
How about adding a de-activate Button to your form using this script:
Private Sub CommandButton1_Click()
UserForm1.Hide
MsgBox "hit OK to continue", vbOKOnly, "Script Paused"
UserForm1.Show
End Sub
I am trying to monitor a sheet which has several text boxes on it.
The idea behind it is the user enters text into these boxes and then you can click the submit button to send it all to a sql database.
Now I want to have it so if the user has made changes, and they go to leave the sheet a macro is triggered to tell them that they haven't saved it.
I've already got this triggering on the deactivate worksheet event, but I was wondering if I can monitor all of the textboxes on the sheet (oleobjects) under one change event
I am already assuming this isn't possible with just one but was hoping.
Thanks in advance
Tom
One way to do this would be to write a separate subroutine that is called within the Change event of all the Textboxes. Keep in mind though that this will be raised every time the Textboxes change at all- every keystroke.
In each TextBox_Change Event:
Private Sub TextBox1_Change()
TextChanged TextBox1
End Sub
New subroutine:
Sub TextChanged(fromTextBox As TextBox)
'validation code goes here
End Sub
I have faced one problem in Excel 2013. In my project, I have a userform that contains a listbox which lists names of all opened excel books.
When a user clicks on a particular name in the list, the appropriate book is activated. So the userform is always on top and while the user is clicking on the names in the list, he can see all opened workbooks getting activated one by one behind the active userform.
This is the way it used to work in Excel 2010.
Now, after upgrade from 2010 to 2013, if a user clicks on a name in the list, selected workbook gets activated but the userform disappears.
What exactly has been broken in Excel 2013 and what is the way to bypass this problem?
Yes, the default behavior has changed. In Pre Excel 2013, The different workbooks are shown within one main Excel window if opened in the same instance. But in Excel 2013, they are shown in their own window. And because of this a modeless userform will only be visible on top of the workbook that was active when the userform was loaded.
And I don't think this has a fix yet. It is by design and may not be fixed.
#Siddharth, based on what you said, I think I have a solution. When you open a form, it will only show up on top of the ActiveWorkbook. As long as all the code is in the same code thread (not sure if terminology is right) , you're stuck with the same workbook; But if you use the Application.Run or Application.Ontime commands it seems to start it's own code thread, which is independent enough to work. Just Activate the workbook/sheet first, and then Unload the form and remote call the macro that showed the form in the first place.
Unfortunately, you need to use Unload instead of Hide, because of the aforementioned issue; which means you need to save any/all options selected.
Private Sub lstFiles_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ThisWorkbook.Application.Workbooks(lstFiles.Text).Activate
Unload Me
Application.Run "USER_Macro1"
'Application.OnTime Now(), "USER_Macro1"
End Sub
Private Sub USER_Macro1(Optional Control) ' As IRibbonControl)
ModelessForm.Show vbModeless
End Sub
I tested it in Excel 2013 and so far it even seems to work regardless of the Screenupdating = false issue seen elsewhere.
Here's my problem: I have two workbooks, one is mine, say Projet.xlsm, and the other is not, say Query.xlsm. Query.xlsm is shared between me and a lots of people in my company so I can't modify it.
My project.xlsm aims to plot some datas extracted with Query.xlsm. My job is to make it an automated process.
How Query.xlsm work: on the first sheet there is some options to select; then we have just to click a button on the first sheet. Finally all the datas are extracted and appears in second sheet.
I've built a macro in project.xlsm wich open Query.xlsm and select the options I want.
Now I'm tryi,g to "click the button" (sheet1 in Query.xlsm) from my macro in my project.xlsm. I've tried things like this: running excel macro from another workbook
But I think I have to mention the name of my sheet somewhere.
Thanks in advance
Assuming you have the workbook open (which it sounds like you do), this worked for me even on a Private CommandButton Sub.
Workbooks("Query.xlsm").Sheets("Sheet1").CommandButton1 = True
Workbooks("Query.xlsm").Sheets("Sheet1").CommandButton1 = vbClick
You may create a public procedure in Query.xlsm Workbook in first sheet.
cmdClick refers to the name of activex command button. Below is sample code.
Public Sub cmdClick()
CommandButton1_Click
End Sub
You can call this procedure from project.xlsm using below syntax.
Workbooks("testing.xlsm").Sheets("Sheet1").cmdClick