- ©«¤l
- 9
- ¥DÃD
- 6
- ºëµØ
- 0
- ¿n¤À
- 22
- ÂI¦W
- 0
- §@·~¨t²Î
- XP
- ³nÅ骩¥»
- XP
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- ¨Ó¦Û
- TAIWAN
- µù¥U®É¶¡
- 2011-9-12
- ³Ì«áµn¿ý
- 2016-5-4
|
[µo°Ý] ½Ð°Ý±q¸ê®Æ®w¶×¥X¸ê®Æ¨ìexecl·|¥X²{»yªk¿ù»~
¦]§Ú¬Oµ{¦¡¤£±j¡A¥u¯à§äºô¸ô¤Wªº½d¨Ò¨Ó§ï²³æªºµ{¦¡
¥H¤U¸ê®Æ¬O¦bºô¸ô¤W§äªº½d¨Ò¡A¦ý¤£ª¾¤Ö¤Fþ¨Ç»yªk¡A¤]§ä¤Fº¡¦h¸ê®Æ
´N¬O¤£ª¾¤Ö¤Fþ¨Ç»yªk¡A¤~·|³y¦¨µLªk¥¿±`°õ¦æ¡C
*³o¦¸¼¶¼gªº¥\¯à¬O¦b¸ê®Æ®ØA1¿é¤JID , µM«áA2«h·|Åã¥Ü¸Ó¨Ï¥ÎªÌ¦WºÙ*
¦b½s¿è¾¹ªº¥ªÃä , ¿ï¾Ü§A·Qn¿é¤J¸ê®Æ©Ò¦bªº¤u§@ªí , ³Ì²³æ´N¬OÂI¨â¤USheet1
¦b¥kÃ䥴¤W¤U¦C¸ê®Æ , ³o¬qªº·N«ä¬On°»´ú¥L¥un¤u§@ªíÄæ¦ì¦³§ó°Ê(°²³]¥L¿é¤J¹LÈ)
§â¥¦ExcelªºÄæ¦ì¦ì¸m±µ¦¬ , §PÂ_¬O§_¬OA1³oÓÄæ¦ì , ¦pªG¬O , ±Ò¥ÎSearch³oӨ禡¨Ó·j´M
¦bExcel¸Ì , Äæ¦ì¬O³z¹LRange¨Óªí¥Ü , ¦Ó¤£ºÞ¬OColumn©Î¬ORow , ³£¬O±q1¶}©l
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 and Target.Row=1 Then
Search (Target.Text)
End If
End Sub
±µ¦¬¨ì¨Ó¦Û¤Wzªº·j´Mn¨D , ¶i¸ê®Æ®w·j´M , ¨Ã±N¦^¶ÇȥᵹA2Äæ¦ì(¦bExcel¸Ì , Äæ¦ì»Ý¿ï©wSelect¤~¥i§â¸ê®Æ¶K¤W , ActiveCell.FormulaR1C1¥Nªíµ¹¿ï©wÄæ¦ì¶K¤W³oӰʧ@¡^
Sub Search(ByVal id As String)
Dim conn As ADODB.ConnectionDim dbRecset As ADODB.Recordset
Dim sSQL As StringDim ss As String
ªì©l¤Æ
Set dbRecset = New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=127.0.0.1;PORT=3306;DATABASE=test;UID=XXX;PASSWORD=OOO;OPTION=3"
conn.Open
sSQL = "SELECT * FROM Table where id='" & id & "'"
dbRecset.CursorLocation = adUseClient
dbRecset.Open Source:=sSQL, ActiveConnection:=conn, CursorType:=adOpenForwardOnly, LockType:=adLockReadOnly, Options:=adCmdTextdbRecset.MoveFirst
¨ú¸ê®Æ
While Not dbRecset.EOF
Range("A2").Select
ActiveCell.FormulaR1C1 = dbRecset(1)
dbRecset.MoveNext
Wend
dbRecset.Close
End Sub
¦sÀÉ«á , ¦^¨ì¸ê®Æªí , ¦bA1¤W¥´ID , A2´N¥i¥HÅã¥ÜName¤F^^
ps 1 ¸ê®Æ®wªº¸ê®Æªí´N«Ü³æ¯Âªº«Ø¥ß¸ê®Æ , ¤£»ÝnÔ£ÃB¥~³]©w
Ps 2 ¦pªGn³s¨ì§Oªº¹q¸£ , °O±o¹ï¤èn¶}3306 , Excel¥²¶·±Ò¥Î³oÓªí³æªº¥¨¶°¥\¯à(¬°¤F¦w¥þ²z¥Ñ , ¦³¨Ç§t¦³¥¨¶°ªºExcelÀÉ®× , ¶}±Ò®É¥¨¶°¹w³]Ãö³¬ , »Ý¤â°Ê¶}±Ò |
|