1. Basic concepts of VBA - "Excel VBA program development self-study collection"

1.1 Common objects and meanings

object name meaning
application The entire Excel application
window window
worksheet  a worksheet
sheets Collection of all worksheets of the specified workbook
shaperange shape area
pivottable pivot table
workbook work log
shape Objects in the drawing layer
range a cell, row, column, selection
name cell range definition name
chart chart
filedialog file dialog
commandbarpopup A popup control on the command bar
commandbar a command bar

 

 

 

 

 

 

 

 

 

 

 

1.2 List of worksheets methods

name illustrate
add New worksheet
copy Copy the worksheet to another location in the workbook
delete delete object
fileacrosssheets Copy a range of cells to the same location on all other sheets in the collection
move Move the worksheet to another location in the workbook
printout print object
printpreview Printing preview
select select object

 

 

 

 

 

 

 

1.3 Event Classification

object event
application application events
workbook workbook events
worksheet worksheet events
chart Chart events
userform form event
label Label events (controls in forms)
image image event

 

 

 

 

 

 

1.4 Character processing functions

keywords effect
strcomp String similarity judgment
strconv String type conversion
lcase   ucase case conversion
space   string repeat string
len Calculate string length
format set character format
lset   rset rearrange string
instr   left   ltrim   mid   right   rtrim   trim  like handle strings
split jion Split and concatenate strings

 

 

 

 

 

 

 

 

example


 

  sub strcomp()

  msgbox strcomp("ABCD","abcd",1) 'parameter 1 is a text comparison, case-insensitive, returns 0, indicating equality

  msgbox strcomp("ABCD","abcd",0) 'parameter 0 is compared in binary and returns -1, indicating that the former is less than the latter

  end sub


 

  sub strconv()

  msgbox strconv("English",vbuppercase) ' to uppercase

  &chr(10) & strconv("English",vblowercase) 'Convert to lowercase

  &chr(10) & strconv("English",vbpropercase) 'Only the beginning is capitalized

  end sub


 

  sub case conversion ()

  msgbox lcase("HELLO")

  msgbox ucase("hello")

  end sub


 

  sub repeat n times ()

  msgbox string(5,"*") 'return "*****"

  msgbox string(4,"China") 'Return "中中中中" only repeat the left one

  end sub


 

  private sub textbox1_change()

    if len(textbox1.text)>0 then

      if right(textbox1.text,1) like "[az]" then exit sub else me.textbox1=left(textbox1.text,len(textbox1.text)-1) 'Like usage, find help documentation for details

    end if

  end sub

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325136297&siteId=291194637