VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create...
Transcript of VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create...
![Page 1: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/1.jpg)
VBA GUI Lesson
Spring 2008
![Page 2: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/2.jpg)
We can create a variety of interfaces in Excel with VBA
Examples include:
Buttons to run macros
Drop down menus
Entire forms
We’ve seen the buttons and menus, so let’s take a look at forms
![Page 3: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/3.jpg)
Consider a sheet for storing and manipulating melt temperatures of elements
![Page 4: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/4.jpg)
This form allows users to input a new element and melting temperature
Once the form is open, you can either Cancel the form, or enter data and save it to the sheet
I’ll explain how to create the form
![Page 5: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/5.jpg)
![Page 6: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/6.jpg)
Go to the Visual Basic Editor
Then do Insert/User Form
This will open up a blank form
![Page 7: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/7.jpg)
![Page 8: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/8.jpg)
Things like background color, caption, etc. are changed in the Properties Box in the lower left
Note the name of the form (This one is UserForm1)
![Page 9: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/9.jpg)
To add Buttons and Text Boxes, go to View/Toolbox and then click on whatever element you want to add
My form had two labels, two textboxes, and two buttons
![Page 10: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/10.jpg)
Just click on a button to edit code that will be executed when the button is clicked
For the Cancel button, the only code is
Unload UserForm1
![Page 11: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/11.jpg)
Private Sub CommandButton1_Click()
Columns("A").End(xlDown).Select
ActiveCell.Offset(1, 0).Value = TextBox1.Text
ActiveCell.Offset(1, 1).Value = TextBox2.Text
ActiveCell.Offset(1, 2).Value = "K"
Unload UserForm1
End Sub
![Page 12: VBA GUI Lesson Spring 2008 - Problem Solving with Excel ...VBA GUI Lesson Spring 2008 We can create a variety of interfaces in Excel with VBA ... Proiect - VBAProiect T oolbox Bookl](https://reader031.fdocuments.in/reader031/viewer/2022041909/5e6674c83238cd0a315d2099/html5/thumbnails/12.jpg)
You’ll also need a button in the worksheet to open the form
The code should be Userform1.Show