userform

Call from one file a UserForm in another

懵懂的女人 提交于 2019-11-29 08:49:42
Write VBA code that calls a UserForm of one Excel file to all the other Excel files present in a folder called john and the master Excel (consists of the following code and the user form) is present in a different location: Private Sub Workbook_OnClick() Dim mypath As String Dim file As String Dim wb As Workbook Dim pat As String Application.ScreenUpdating = False ChDrive "C:" ChDir "C:\Users\Administrator\Desktop\John" 'john is a folder that consists of the excel files mypath = Range("B1").Value 'mypath has the same value as chDir file = Dir(mypath & "\" & "*.xlsx") Do While file <> "" Set wb

Calling a userform and returning a value

我只是一个虾纸丫 提交于 2019-11-28 13:37:14
I have a vba code thats Auto_Open. It does some checks then prompts a userform that asks for username and password. I called this userform with userform_name.show . My issue is how can I return a Boolean to my Auto_Open sub from the userform code. I linked the code that verifies if the credentials are correct to the "Login" button on the form. this is the code that produces the Boolean. I need to return it to the Auto_Open. Private Sub loginbutton() Dim bool As Boolean Dim lrup Dim r As Long Dim pass As String loginbox.Hide 'are fields empty Do While True If unBox.Text = "" Or pwBox.Text = ""

How to detect a mouse_down on a Userform Frame while the mouse is still down

霸气de小男生 提交于 2019-11-28 12:02:18
问题 I want to detect when there's a mouse_down on any Frame on the Form while the mouse is still down. I know how to do it for a Click, but I want to catch it before mouse_up. Thanks 回答1: You can create a _MouseDown event handler for each frame on the form, or if you have many frames you can create a generic event handler class Create a Class module (eg named cUserFormEvents ) Public WithEvents Frme As MSForms.frame Public frm As UserForm Private Sub Frme_MouseDown( _ ByVal Button As Integer, _

Timer on user form in Excel VBA

杀马特。学长 韩版系。学妹 提交于 2019-11-28 09:15:22
问题 I've got some old Excel VBA code where I want to run a task at regular intervals. If I were using VB6, I would have used a timer control. I found the Application.OnTime() method, and it works well for code that's running in an Excel worksheet, but I can't make it work in a user form. The method never gets called. How can I make Application.OnTime() call a method in a user form, or are there other ways to schedule code to run in VBA? 回答1: I found a workaround for this. If you write a method in

How To Display Part of Excel on VBA Form

有些话、适合烂在心里 提交于 2019-11-28 03:33:26
问题 I have a file on .csv format and from A-S columns, it has some records like a table. My complete program will insert/remove/delete/add some rows, columns and editing cell values etc. I managed to code all the operations that i need, now i'm trying to integrate it with a gui. What I want is to display cells from Ax1 to the last column that has record on VBA user form. How can i do that? *ps: again, my file's format is .csv and I am using Excel 2007 回答1: You can use a multi column Listbox to

Modeless form that still pauses code execution

左心房为你撑大大i 提交于 2019-11-28 00:18:17
Is there anyway to have a userform that acts modeless, while still pausing code execution like a modal form? I'd like the userform to show, but still allow interaction with the parent program. Modal forms block interaction with the parent program. A modeless form would work, but I would like the code execution to pause while the form is up. I've worked around this by creating an infinite loop that checks if the form is visible, but that seems a bit hacky. Public Sub GetFormInfoAndDoStuff ufForm.show vbModeless Do while ufForm.Visible DoEvents Loop ' Do other stuff dependent on form End Sub

Adding controls to a frame in an Excel userform with VBA

杀马特。学长 韩版系。学妹 提交于 2019-11-27 23:39:19
I need to create labels and buttons dynamically and then add them to a frame within a userform. How do I do this? Seems like it should be easier than it really is. The following code demonstrates how you can dynamically populate a frame in a userform with controls... In the form I used I had a frame control named Frame1, so in the UserForm_Initialize you call Frame1.Controls.Add to embed a control in the frame. You can set the control which gets returned to a WithEvents control variable that you have defined in the UserForm code module so you can respond to events on whatever controls you want

Excel VBA Open workbook, perform actions, save as, close

别等时光非礼了梦想. 提交于 2019-11-27 21:35:16
This question has been edited due to lengthy comments and updates from proposed answers. As requested here is module 13; Sub SaveInFormat() Application.DisplayAlerts = False Workbooks.Application.ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\jammil\Desktop\AutoFinance\ProjectControl\Data\" & Format(Date, "yyyymm") & "DB" & ".xlsx", leFormat:=51 Application.DisplayAlerts = True End Sub Also there are issues with the errorhandling, I know I've gone wrong with it but I'm more interested in fixing the close function at the moment before I get into it. Here is the error handling code

Excel VBA Userform - Execute Sub when something changes

前提是你 提交于 2019-11-27 08:46:38
I have a userform containing lots of text boxes. When ever the values of these text boxes changes, I need to recalculate my end result values based on the textbox values by calling a subroutine AutoCalc(). I have around 25 boxes and I don't want to add a Change() event individually to each textbox calling the said subroutine. What's the quickest and efficient way to call the AutoCalc() whenever some value changes? This can be achieved by using a class module . In the example that follows I will assume that you already have a userform with some textboxes on it. Firstly, create a class module in

Calling a userform and returning a value

℡╲_俬逩灬. 提交于 2019-11-27 07:47:11
问题 I have a vba code thats Auto_Open. It does some checks then prompts a userform that asks for username and password. I called this userform with userform_name.show . My issue is how can I return a Boolean to my Auto_Open sub from the userform code. I linked the code that verifies if the credentials are correct to the "Login" button on the form. this is the code that produces the Boolean. I need to return it to the Auto_Open. Private Sub loginbutton() Dim bool As Boolean Dim lrup Dim r As Long