This document provides an overview of macros and VBA in Excel. It discusses how Excel objects like workbooks, worksheets and cells can be automated using VBA macros. Macros allow repetitive tasks to be standardized and errors to be reduced. The document demonstrates how to record, write, run and debug VBA macros. It also covers topics like loops, variables, userforms and hiding/showing sheets dynamically with macros. Best practices discussed include using message boxes for debugging, avoiding select statements, and proper use of quotes and sheet references.
Dokumen tersebut memberikan penjelasan mengenai Excel VBA Macro, mulai dari pengenalan makro, cara membuat makro, menggunakan Excel Macro Recorder, dasar-dasar VBA seperti variabel, pernyataan if-then, looping, objek workbook dan worksheet, hingga pembuatan kontrol seperti textbox, listbox, checkbox, dan userform.
The value of "a.value" will be printed to the VBA Immediate window when that line is executed. The Debug.Print statement sends its output to the Immediate window, which is useful for inspecting variable values while code is running without stopping the execution.
This document provides an overview of VBA Excel Level II topics including: arrays, if/then statements, loops, debugging, string operations, subroutines, functions, passing variables by value vs reference, dictionaries and collections for storing multiple data types, using range objects to reference cells, and creating basic userforms with command buttons and event handlers. The lab examples demonstrate how to write VBA code to search arrays, loop through a range looking for names, create subroutines to consolidate repeated code, store employee data in a dictionary for easy lookup, and build a userform with input and output functionality.
A macro is a series of functions written in a programming language that is grouped in a single command to perform the requested task automatically. Excel macros are used to save time and reduce the possibility of human error by automating repetitive processes.
This is a slide deck I created for Mike Thomas as an introduction to his presentation for MacBites Learning - Excel Macro Magic. A video of the presentation is available from http://macbiteslearning.co.uk/excel-macro-magic-webinar-recording/
This presentation will give you a brief introduction to Excel Macros. Also it covers step by step instructions on how to record a Macro in Excel 2007 & execute the same.
This document provides an overview of macros and VBA in Excel. It discusses how Excel objects like workbooks, worksheets and cells can be automated using VBA macros. Macros allow repetitive tasks to be standardized and errors to be reduced. The document demonstrates how to record, write, run and debug VBA macros. It also covers topics like loops, variables, userforms and hiding/showing sheets dynamically with macros. Best practices discussed include using message boxes for debugging, avoiding select statements, and proper use of quotes and sheet references.
Dokumen tersebut memberikan penjelasan mengenai Excel VBA Macro, mulai dari pengenalan makro, cara membuat makro, menggunakan Excel Macro Recorder, dasar-dasar VBA seperti variabel, pernyataan if-then, looping, objek workbook dan worksheet, hingga pembuatan kontrol seperti textbox, listbox, checkbox, dan userform.
The value of "a.value" will be printed to the VBA Immediate window when that line is executed. The Debug.Print statement sends its output to the Immediate window, which is useful for inspecting variable values while code is running without stopping the execution.
This document provides an overview of VBA Excel Level II topics including: arrays, if/then statements, loops, debugging, string operations, subroutines, functions, passing variables by value vs reference, dictionaries and collections for storing multiple data types, using range objects to reference cells, and creating basic userforms with command buttons and event handlers. The lab examples demonstrate how to write VBA code to search arrays, loop through a range looking for names, create subroutines to consolidate repeated code, store employee data in a dictionary for easy lookup, and build a userform with input and output functionality.
A macro is a series of functions written in a programming language that is grouped in a single command to perform the requested task automatically. Excel macros are used to save time and reduce the possibility of human error by automating repetitive processes.
This is a slide deck I created for Mike Thomas as an introduction to his presentation for MacBites Learning - Excel Macro Magic. A video of the presentation is available from http://macbiteslearning.co.uk/excel-macro-magic-webinar-recording/
This presentation will give you a brief introduction to Excel Macros. Also it covers step by step instructions on how to record a Macro in Excel 2007 & execute the same.
16. 讀取資料筆數讀取資料筆數 (3)(3)
而利用而利用 ListCountListCount 及及 List(List( 位置位置 )) 兩種方兩種方
法,我們可以列出清單方塊的所有資料法,我們可以列出清單方塊的所有資料
,如下:,如下:
For I = 0 To List1.ListCount - 1
Print List1.List(I) ' 印出第 I 筆資料
Next I
21. 使用清單方塊使用清單方塊 ---- 實例練習實例練習 (2)(2)
參考上圖 置好控制元件,然後在「輸佈參考上圖 置好控制元件,然後在「輸佈
入」命令鈕之中撰寫以下程式:入」命令鈕之中撰寫以下程式:
其實這兩行敘述還可以合併成一行,如下其實這兩行敘述還可以合併成一行,如下
::Private Sub Command1_Click()
List1.AddItem Text1.Text
End Sub
Private Sub Command1_Click()
X = Text1.Text ' 讀取使用者輸入的資
料
List1.AddItem X ' 將資料加入於 ListBox
End Sub
24. 讀取使用者選取的資料讀取使用者選取的資料 (2)(2)
例如:例如:
但如果沒有資料被選取,例如程式剛執行時,但如果沒有資料被選取,例如程式剛執行時,
則則 TextText 屬性 等於空字串值屬性 等於空字串值 (“”)(“”) ,而,而 ListIndexListIndex
屬性 等於值屬性 等於值 -1-1 。。
Li st 1. Text 等於 " Thomas"
Li st 1. Li st I ndex 等於 2
使用者選取了第2 筆資料
,資料內容為" Thomas"。
32. 實例應用實例應用 ---- 字型選擇程式字型選擇程式 (2)(2)
以下是程式完成的過程:以下是程式完成的過程:
1.1. 首先是參照上圖 置控制元件,並設定以下屬性:佈首先是參照上圖 置控制元件,並設定以下屬性:佈
控制元件 屬 性 屬 性 值
Label1 Caption
字型:
Arial
Courier
Ms Sans
Serif
System
Times
New
Roman
細明體
Command1 Caption
改變字型
List1 List
33. 實例應用實例應用 ---- 字型選擇程式字型選擇程式 (3)(3)
2.2. 在在改變字型改變字型命令鈕裡面讀取使用者選取的字型,命令鈕裡面讀取使用者選取的字型,
然後將字型設定成表單的字型:然後將字型設定成表單的字型:
以上程式中「以上程式中「 F = List1.TextF = List1.Text 」及「」及「 Font.Name =Font.Name =
FF 」兩行敘述也可以合併寫成:」兩行敘述也可以合併寫成:
Private Sub Command1_Click()
F = List1.Text ' 讀取使用者選取的字型
Font.Name = F ' 設定表單的字型
Print F ' 順便印出來看看
End Sub
Font.Name = List1.Text
37. 實例應用實例應用 ---- 挑選「虎膽妙算」成員挑選「虎膽妙算」成員
(3)(3)
2.2. 在在選取人員選取人員命令鈕裡讀出使用者選取了命令鈕裡讀出使用者選取了
些人員:哪些人員:哪
Private Sub Command1_Click()
For I = 0 To List1.ListCount - 1
If List1.Selected(I) Then
Print List1.List(I)
End If
Next
End Sub
40. 實例應用實例應用 ---- 資料輸入程式加強版資料輸入程式加強版
(2)(2)
承續上一節的資料輸入程式,在表單上佈承續上一節的資料輸入程式,在表單上佈
置「刪除」及「全數刪除」命令鈕,然後置「刪除」及「全數刪除」命令鈕,然後
撰寫以下程式:撰寫以下程式:
Private Sub Command2_Click() ' 刪除
If List1.ListIndex >= 0 Then
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command3_Click() ' 全數刪除:清
除
List1.Clear
End Sub
57. 排序實例排序實例 p.354 – Step 2p.354 – Step 2
將將 Command1_ClickCommand1_Click 的程式修改如的程式修改如
下:下:
Private Sub Command1_Click()
For I = 0 To List1.ListCount - 1
If Val(Text1.Text) < Val(List1.List(I))
Then
Exit For
End If
Next I
List1.AddItem Val(Text1.Text), I
End Sub