You are on page 1of 26

VBA

q Excel
1.

2.

3.

Excel

(DDE)
( Ctrl+C ) Excel
Web Ctrl+V
7.1.1 7.1.2

Microsoft Excel ( 7.1.3 )

7.1.1

7.1.2

7.1.3
1

PDF created with pdfFactory Pro trial version www.pdffactory.com

4. 7.1.4 Excel Web

7.1.4

() 7.1.5
?

Excel

7.1.5

1. Excel

(
)
()

(
Black-Scholes )
Excel Web Web
2

PDF created with pdfFactory Pro trial version www.pdffactory.com

()(
)
Excel

2. Excel
Excel

Excel
3. Excel

(Mark to market) Excel


Excel

(DDE) Excel
Excel
()

Excel Excel

(!)
Excel
?
1. Excel
Excel
Excel Excel Excel

?
Excel(Excel Application) OnTime
OnTime OnTime
(OnTime )
Private Sub ExeSelf( )
On Error Resume Next
i=i+1
Cells(i,1) = Time
Application.OnTime Now + TimeValue(00:00:01), ThisWorkBook.ExeSelf
End Sub
3

PDF created with pdfFactory Pro trial version www.pdffactory.com

ExeSelf On Error Resume Next

i = i + 1 Time Cells(i,1) =
Time(i
)
Application.OnTime Now + TimeValue(00:00:01),
ThisWorkBook.ExeSelf Application (Excel ) OnTime
(NOW) 1 (TimeValue(00:00:01))(
)(ThisWorkBook) ExeSelf ()

Private Sub Workbook_Open( )


Call ExeSelf
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)


On Error Resume Next
Application.OnTime Now + TimeValue(00:00:01), _
ThisWorkBook.ExeSelf, , False
End Sub
OnTime False
3 4
ThisWorkBook (
ParaTest.xls)
Dim i As Single
Private Sub Workbook_Open()
Call ExeSelf
End Sub
Private Sub ExeSelf()
On Error Resume Next
i=i+1
Cells(i, 1) = Time
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf", , False
End Sub
7.1.6

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.1.6
7.1.6 ?
Cells(i, 1) = TimeWorksheets(Sheet2).Cells(i, 1) =
Worksheets(Sheet1).Cells(1,1) Sheet1 Cells(1,1)
Sheet2
(RTDataCollect.xls
) Web (
Web ) Excel http://tw.stock.yahoo.com/s/list.php?
1 ThisWorkbook

Dim i As Single
Private Sub Workbook_Open()
Call ExeSelf
End Sub
Private Sub ExeSelf()
On Error Resume Next
i=i+1

If i = 1 Then
'
Sheets(2).Cells(1, 1) = "Weight"
Sheets(2).Cells(1, 2) = 0.2
Sheets(2).Cells(1, 3) = 0.2
Sheets(2).Cells(1, 4) = 0.1
Sheets(2).Cells(1, 5) = 0.1
Sheets(2).Cells(1, 6) = 0.1
Sheets(2).Cells(1, 7) = 0.1
Sheets(2).Cells(1, 8) = 0.1
Sheets(2).Cells(1, 9) = 0.1
Sheets(2).Cells(1, 10) = "Portfolio Value"
5

PDF created with pdfFactory Pro trial version www.pdffactory.com

'
Sheets(2).Cells(2, 1) = "Time"
Sheets(2).Cells(2, 2) = Sheets(1).Cells(11, 2)
Sheets(2).Cells(2, 3) = Sheets(1).Cells(13, 2)
Sheets(2).Cells(2, 4) = Sheets(1).Cells(14, 2)
Sheets(2).Cells(2, 5) = Sheets(1).Cells(15, 2)
Sheets(2).Cells(2, 6) = Sheets(1).Cells(16, 2)
Sheets(2).Cells(2, 7) = Sheets(1).Cells(17, 2)
Sheets(2).Cells(2, 8) = Sheets(1).Cells(18, 2)
Sheets(2).Cells(2, 9) = Sheets(1).Cells(19, 2)
i=i+2
End If
Sheet1
Sheets(2).Cells(i, 1) = Time
Sheets(2).Cells(i, 2) = Sheets(1).Cells(11, 4)
Sheets(2).Cells(i, 3) = Sheets(1).Cells(13, 4)
Sheets(2).Cells(i, 4) = Sheets(1).Cells(14, 4)
Sheets(2).Cells(i, 5) = Sheets(1).Cells(15, 4)
Sheets(2).Cells(i, 6) = Sheets(1).Cells(16, 4)
Sheets(2).Cells(i, 7) = Sheets(1).Cells(17, 4)
Sheets(2).Cells(i, 8) = Sheets(1).Cells(18, 4)
Sheets(2).Cells(i, 9) = Sheets(1).Cells(19, 4)
Application.OnTime Now + TimeValue("00:02:00"), "ThisWorkBook.ExeSelf"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime Now + TimeValue("00:02:00"), "ThisWorkBook.ExeSelf", , False
End Sub
7.1.7 2
7.1.8

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.1.7

7.1.8
2.
Excel

Sheet2 A1 Sheet1 B5 ( Sheet1


) Sheet2 A1 =Sheet1!B5
=[Book1.xls]Sheet2!C3
Book1.xls Sheet2 C3 Book1.xls

3.
()

PDF created with pdfFactory Pro trial version www.pdffactory.com

Excel
Excel
Excel Excel
( VB C)

q Excel

1. () Excel

2.
7.2.1
()
()
B4 C4
B11 (1101 ) D11 ( 1101
) 7.2.1 B4 =!B11
C4 =!D11 7.2.1

3. 7.2.1 <=23.5
>=6.5
(1) ( C4) Excel
7.2.2
23.5()

(2) >=23.55
7.2.2
7.2.3
( 7.2.5
)
(3)

7.2.4
(4) IF

J4 =IF(C4<=23.5,"",IF(C4>=23.55,"",""))
J4 C4 7.2.5

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.2.1

7.2.2

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.2.3

7.2.4

7.2.5
Excel

1. Excel
7.2.6
()

10

PDF created with pdfFactory Pro trial version www.pdffactory.com

2.

7.2.6

LCD CRT LCD+CRT




7.2.7 7.2.7 ( 7.2.8)
7.2.9 Intel(R) Extreme Graphics 2 for Mobile
( 7.2.10)
( 7.2.11) 7.2.12
VBA 7.2.11

7.2.8

7.2.7

11

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.2.11
7.2.9

7.2.12

3.

4.

7.2.10
Excel 7.2.13

7.2.13

7.2.14

12

PDF created with pdfFactory Pro trial version www.pdffactory.com

5.

7.2.14
Excel
7.2.15
7.2.16

7.2.15

13

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.2.16
6.

7.

8.

A
B 1 2 C3

(
)

(1)

(CommandButton)
7.2.17 (2)(
) 7.2.18 (3)(

) 7.2.19
(ActiveWindow.Zoom = 100
100)(iv) Excel

50
( 7.2.20 ) 7.2.20 100%

( 200
)

7.2.17
14

PDF created with pdfFactory Pro trial version www.pdffactory.com

7.2.18

7.2.19

7.2.20

15

PDF created with pdfFactory Pro trial version www.pdffactory.com

qExcel VBA

qOnTime
Application OnTime

(DDE) Excel

OnTime

1. (000000)
Now + TimeValue(time) ()
TimeValue(time)
2.
Sub myTest
Msgbox
Application.OnTime Now + TimeValue("00:00:03") , myTest
End Sub

Dim myTime As Date


Sub myTest
Msgbox
myTime = Now + TimeValue("00:00:03")
Application.OnTime myTime , myTest
End Sub
myTest 3 myTest

OnTime
OnTime Excel
Schedule False
Workbook_beforeClose OnTime
OnTime
Private Sub Workbook_BeforeClose
On Error Resume Next
Application.OnTime Now + TimeValue("00:00:10") , myTest, Schedule:=False
End Sub
qWorksheet_calculate
Worksheet
Calculate Worksheet
16

PDF created with pdfFactory Pro trial version www.pdffactory.com

Calculate
OnTime
Calculate
Private Sub Worksheet_Calculate()
Msgbox
End Sub
Calculate
Worksheet_Calculate

Private Sub Worksheet_Calculate()


If ThisWorkbook.WorkSheets(sheet1).cells(1,1) Mod 10 Then
Msgbox

Else
Exit sub
End if
End Sub
Calculate
OnTime

4-4
4- 4 OnTime Worksheet_Calculate DDE
DDE

Ontime

Worksheet_Calculate

Application.Ontime_
Now+TimeValue("00:00:01") private Sub Worksheet_Calculate
Excel2002
Excel2002

17

PDF created with pdfFactory Pro trial version www.pdffactory.com

q
q
1()
2
3- 3

DDE

RTF(Road

to The

Future)
RTF(Road

to The

Future)
*

*
*

/HTS

/HTS
*

*
*

2007 3 (?)

3()()
q
DDE

5-1
5- 1

Yahoo
PCHOME

2007 4 11

AM 845 PM 145

2007 4 18

18

PDF created with pdfFactory Pro trial version www.pdffactory.com

RAM

Intel(R) Pentium(R) 4 CPU2.8 GHz


256 MB
Intel(R) PRO/100 VE Network Connection
Microsoft Window XP Professional
Version2002

Service Pack2

Microsoft Office Excel 2003

40

IE

yahooPchome

PCHOME
YAHOO
5 20 YAHOO
YAHOO

YAHOO

PCHOME

(1)
(2)(3)

q I
19

PDF created with pdfFactory Pro trial version www.pdffactory.com

6- 2
3

2.

6- 6

20

PDF created with pdfFactory Pro trial version www.pdffactory.com

1.

6-7

6- 8

6-9

6- 9
3

6- 10
21

PDF created with pdfFactory Pro trial version www.pdffactory.com

6- 11

6- 12

6- 13

6- 14

6- 15

6- 16

22

PDF created with pdfFactory Pro trial version www.pdffactory.com

q II
q

1.
2.
6- 10 CB

CB ()

T+2

CB CB

T+3

CBEC

T+8

T+9

S+1

()

S+2

6- 17

23

PDF created with pdfFactory Pro trial version www.pdffactory.com

6- 20

24

PDF created with pdfFactory Pro trial version www.pdffactory.com

4/

CB

10
20

6- 21

6- 22

6- 23

25

PDF created with pdfFactory Pro trial version www.pdffactory.com

q
q
1()
2
3
4()
5
6
7
q
1 =
2
3
4 ( S + C )(1 k ) F ( S + C )(1 + k )
5 DDE Web Connection
q
(
)

( 35 )

Step by Step Step by Step II

26

PDF created with pdfFactory Pro trial version www.pdffactory.com

You might also like