ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ½Ð°Ý±q¸ê®Æ®w¶×¥X¸ê®Æ¨ìexecl·|¥X²{»yªk¿ù»~

[µ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·Q­n¿é¤J¸ê®Æ©Ò¦bªº¤u§@ªí , ³Ì²³æ´N¬OÂI¨â¤USheet1

¦b¥kÃ䥴¤W¤U¦C¸ê®Æ , ³o¬qªº·N«ä¬O­n°»´ú¥L¥u­n¤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


±µ¦¬¨ì¨Ó¦Û¤W­zªº·j´M­n¨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ªG­n³s¨ì§Oªº¹q¸£ , °O±o¹ï¤è­n¶}3306 , Excel¥²¶·±Ò¥Î³o­Óªí³æªº¥¨¶°¥\¯à(¬°¤F¦w¥þ²z¥Ñ , ¦³¨Ç§t¦³¥¨¶°ªºExcelÀÉ®× , ¶}±Ò®É¥¨¶°¹w³]Ãö³¬ , »Ý¤â°Ê¶}±Ò
XX

        ÀR«ä¦Û¦b : ¯u¥¿ªº·R¤ß¡A¬O·ÓÅU¦n¦Û¤vªº³oÁû¤ß¡C
ªð¦^¦Cªí ¤W¤@¥DÃD