Excel VBA-controls, user forms, and common functions

Source: Internet
Author: User

Source: http://blog.csdn.net/alexbnlee/article/details/6913565

Reference: http://msdn.microsoft.com/zh-cn/library/ktwtk9ff%28v=VS.80%29.aspx

TextBoxParts 

→ The syntax of the KeyPress event is as follows:

KeyANSI is only a parameter, so you can change it to any name you like. Every time you type a value, KeyANSI is triggered. By setting it, You can restrict the typing of the write value.
→ KeyDown event triggered by pressing
→ KeyUp event triggered by loose

CommandButtonParts 
→ MouseMove event
→ MouseDown event: press the event. both the left and right keys are available.
→ MouseUp event release mouse event
→ Mouse click event for the MouseClick event. Right-click the event and you cannot

UserFormParts 
→ MouseMove event
→ Initialize event
Unload UserForm1 to close the form

ListBoxParts

Common functions 

→ Instr (2, "eAlex", "e") returns the location where e first appeared in Alex (starts from 1st characters and returns 4)
→ Round (34.566, 2) returns the rounding result of the former retaining two decimal places.
→ Int (34.43) returns the maximum integer not greater than this number.
→ Convert Val ("22.3") to a number
→ Left ("Alex", 3) three characters on the Left
→ Mid ("Alex", 1, 2) Start With Index 1, with a length of 2 Characters
→ Right ("Alex.exe", 3) three characters on the Right

→ Asc ("A") returns an Integer representing the character code of the first letter in the string.
→ Trim ("Alex") removes all spaces
→ LTrim ("Alex") removes the left space
→ Remove right spaces in RTrim ("Alex ")
→Len ("Sleep") calculates the length
→ CInt ("123") to an Integer
→ CStr (123) to String
→ Space (2) Two spaces

→ R = Cells (Rows. Count, 1). End (xlUp). Row get the last Row of content

Range ("A1: A10"). Select
Selection. Copy
Cells (2, 2). Select
ActiveSheet. Paste
Application. CutCopyMode = false': copy the selected area, paste it, and finally retrieve the selected area box.

→ Workbooks. Open "F: \ Desktop \ 1.xls" Open the file
→ ActiveWorkbook. Close savechanges: = True Close the file and save the file
→ ActiveWorkbook. SaveAs Filename: = "F: \ Desktop \ 2.xlsx" Save As a file

TextBox Control 
→ TextBox1.Text
→ TextBox1.SetFocus: move the cursor to TextBox1
→ TextBox1.SelStart specify the starting position of the selected text
→ TextBox1.MaxLength the maximum length that can be entered in the text box
→ TextBox1.MultiLine
→ TextBox1.Top
→ TextBox1.Left
→ TextBox1.Width
→ TextBox1.Height

CommandButton Control

→ CommandButton1.Top
→ CommandButton1.Left
→ CommandButton1.Width
→ CommandButton1.Height

ListBox control

→ Index of the selected text in ListBox1.ListIndex,-1 is not selected, and 0 is the first
→ ListBox1.List (0) content of the first entry
→ ListBox1.ListCount
→ If the value of ListBox1.ListStyle is 1, a box is selected.
→ ListBox1.MultiSelect can be selected if the value is 1

UserForm Control
→ UserForm1.Show
→ Unload UserForm1

ComboBox control
→ ComboBox1.List can be directly assigned values using arrays.
→ ComboBox1.ListIndex = 0 the first text is displayed on ComboBox
→ ComboBox1.Clear remove all content above
→ ComboBox1.AddItem "Beijing" added content

MultiPage Control
→ MultiPage1.Value = 0 the content on the first page is displayed when multiple pages are displayed.
→ MultiPage1.SelectedItem. Index> 2 select a page other than the first page

The difference between the MultiPage control and the TabStrip control is that the former has no relationship between each page, while the latter shares the same page, but the label names are different ~
TabStrip Control

→ TabStrip1.Value = 0 the content on the first page is displayed when multiple pages are displayed.
→ TabStrip1.SelectedItem. Caption different Tab names
→ TabStrip1.SelectedItem. Index of different tabs
→ TabStrip1.Style has three options. The default value is 0, 1, which is in the form of buttons.

Image Control

→ Image1.Picture = LoadPicture (FilPath): loads an image. The FilPath is the complete address of the image.

Dim Arr As VariantDim r As Integerr = Cells(Rows.Count, 1).End(xlUp).RowArr = Range("A1:A" & r)ListBox1.List = Arr

ComboBox has the same usage ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.