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

[Âà¶K] VBAªº¼g§@§Þ¥©»P¼W¶i®Ä¯à

[Âà¶K] VBAªº¼g§@§Þ¥©»P¼W¶i®Ä¯à

VBAªº¼g§@§Þ¥©»P¼W¶i®Ä¯à

¸g¥Ñ¿ý»s²£¥Íªº¥¨¶°¡A³q±`µ{¦¡½X³£·|§t¦³«Ü¦h Select¡A¬Æ¦Ü©¹«á¦Û¤v¼gªºµ{¦¡¤]²ßºD¥Î¤@°ï Select¡C¼gµ{¦¡ªº¤H¥H¬°¥²¶· Select ¤@­Óª«¥ó«á¤~¯à¹ï¥¦°µ³B²z¡A¦ý³o¬O [¿ý»s¥¨¶°] »~¾Éªº¿ù»~Æ[©À (¦Û¤v¤]¨S¦³¹ý©³¤F¸Ñ»yªk)¡A¦Ó¥B¬O³y¦¨¥¨¶°°õ¦æ®Ä²v¤£¨Îªº­ì¦]¤§¤@¡C

¤@¡B¼Æ¼Æ¬Ý§Aªºµ{¦¡¸Ì¦³¦h¤Ö "Select" ?
°£«Dµ{¦¡´N¬O­n¨Ì¨Ï¥ÎªÌ¿ï¨úªºª«¥ó¨Ó°µ°Ê§@¡A§_«h Select ©M Selection ³£¬O¦h¾lªº.
¡· ¼Ð·Çªºª«¥ó±±¨î»yªk¡G
¡@ ª«¥ó.¤èªk¡@¡]¨Ò¦p Range("A1").Copy¡^
¡@ ª«¥ó.ÄÝ©Ê = ­È¡@¡]¨Ò¦p Range("A1").ColorIndex = 15¡^
¦Ó¤£¬O¤@©w­n¥ý Select ª«¥óµM«á¦A¹ï Selection °µ°Ê§@.

Á|¨Ò¦Ó¨¥¡A§A­n½Æ»s Sheet1.A1 ªº­È¨ì Sheet2.B1 --
¡@Range("A1").Copy
¡@Sheets(2).Select
¡@Range("B1").Select
¡@Range("B1").PasteSpecial xlPasteValues
¨ä¹ê¥i¥H³o»ò¼g --
¡@Sheets(2).Range("B1") = Sheets(1).Range("A1")
¦pªG¤º®e»P®æ¦¡³£­n½Æ»s¡A¥i¥H³o»ò¼g --
¡@Sheets(1).Range("A1").Copy Sheets(2).Range("B1")

¤£­n¬Ý³o¨S¤°»ò¡A§AªºVBAÆ[©À©Mµ{«×¯à§_§ó¶i¤@¨B¡A³o¬O«Ü­«­nªº¤@ÂI¡C

¤G¡BÃö³¬¿Ã¹õ§ó·s ¡]Application.ScreenUpdating¡^
µ{¦¡¸Ì°µªº°Ê§@¶V¦h¡A¿Ã¹õ§ó·sªº°ÝÃD´N¶V©úÅã¡C¨Ò¦p¿ï¨ú¤FÀx¦s®æ¡B¿ï¨úª«¥ó¡B½Æ»s¡B¶K¤W¡B¤Á´«¤u§@ªí... Excel ³£·|§ïÅܵJÂI (Focus). ¨C§ïÅܤ@¦¸¡A´N¬O¤@¦¸¿Ã¹õ§ó·s¡C·Q·Q¬Ý¡A¦b¤@³s¦êªº¿Ã¹õ§ó·s¤§¤¤¡A¤£¦ý¥O¨Ï¥ÎªÌ²´ªá¼º¶Ã¡Aµ{¦¡°õ¦æªº¾ãÅé®Ä¯à¤]·|¤U­°¡C

³o»P´î¤Ö Select ¬O¤@Åé¨â­±ªº¨Æ¡A¨ä¹ê«Ü¦h¿ï¨úÀx¦s®æ¡B¿ï¨úª«¥ó¡B½Æ»s¡B¶K¤W¡B¤Á´«¤u§@ªí... ªº°Ê§@³£¬O¤£¥²­nªº¡C¥u­n§Þ¥©¥Îªº¦n¡AScreenUpdating ´X¥G¥i¥H§ô¤§°ª»Õ¡C

¤T¡B¹L¦h/¤£¥²­nªº°j°é¤]·|­°§C°õ¦æ®Ä²v
°j°é (¦p For...Next¡BDo...Loopµ¥µ¥) ¬O«Ü­«­nªº¼g§@§Þ¥©¤§¤@¡A¥¦¯à¤j´T²¤Æµ{¦¡¤¤­«½Æªº°Ê§@¡A¦Ó¥B¬O¿ý»s¤£¥X¨Óªº¡C
³o¸Ì©Ò¿×¤£¥²­nªº°j°é¬O«ü³B²zªº½d³ò¤Ó¤j¡A®ö¶O¹L¦h®É¶¡¡C¨Ò¦p
For Each cell In Columns(1)
¡@......
Next
For Each cell In [A1:A65536]
¡@......
Next
¥H¤W¨â­Ó°j°é³£¬O³B²z A Äæ 6 ¸U¦h­ÓÀx¦s®æ¡C
»¡¹ê¦bªº¡A³s´X¤d­ÓCell§Ú³£¦³ÂI¾á¤ß¤F¡A¦óªp´X¸U­Ó -- ¦³¥²­n¶Ü??
¦ó¤£§PÂ_¦n¸ê®Æªº½d³ò¦A¨Ó°µ°j°é --
For Each cell In Range([A1], [A65536].End(xlUp))
¡@......
Next

°Ñ¦Ò: ¦p¦ó§PÂ_¸ê®Æ½d³ò
http://gb.twbts.com/index.php/topic,315.0.html
http://gb.twbts.com/index.php/topic,584.0.html

¥|¡BÄÀ©ñª«¥óÅܼƦû¥Îªº°O¾ÐÅéªÅ¶¡
¦b³o¸Ì¤×«ü¹ïÀ³¥Îµ{¦¡(Appliation)ªº¤Þ¥Î»P¦s¨ú¡A¤U¨Ò±qWordªí®æ¨ú¦^¸ê®Æ¦ÜExcel¤u§@ªí --

Sub get_word_table( )
Dim wrdApp As Object
Set wrdApp = CreateObject("Word.Application") '«Ø¥ß¤Þ¥ÎWordÀ³¥Îµ{¦¡ªºª«¥ó
Set wrdDoc = wrdApp.Documents.Open("D:\Temp\ole_test.doc") '¤Þ¥ÎWord¤å¥ó
With wrdDoc.Tables(1)
¡@For r = 1 To .Rows.Count
¡@¡@For c = 1 To .Columns.Count
¡@¡@Cells(r, c) = .Cell(r, c)
¡@¡@Next c
¡@Next r
End With
wrdDoc.Close 'close the document
wrdApp.Quit 'close Word
Set wrdDoc = Nothing 'ÄÀ©ñª«¥óÅܼÆ
Set wrdApp = Nothing
End Sub

ªì¾ÇªÌ±`±`·|©¿²¤³Ì«á¨â¥y¡A¦pªG¤£¼gÁöµM¤£·|¼vÅTµ{¦¡ªº¹B¦æ¡A¦ý±q°O¾ÐÅéºÞ²z©M®Ä¯à±±¨îªº¨¤«×¦Ó¨¥¡A³o¬O­Ó«Ü¤£¦nªº²ßºD¡C

·í¬Ù«h¬Ù¡A¬Ùªº¬O¦h¾l­«½Æªºµ{¦¡½X¡F
·í¥Î«h¥Î¡A¥Îªº¬O¤£¥i©Î¯Êªºµ{¦¡½X¡C

--------------------------------------------------------------------------------

¤j®a»{¬°¦³¤£¨¬©ÎºÃ°Ý¤§³B¡AÅwªï´£¥X¸É¥R©M°Q½×¡C

¦^´_ 1# Hsieh


    «e½ú±z¦n ÁÂÁ±z«ü¾É
Set wrdDoc = Nothing 'ÄÀ©ñª«¥óÅܼÆ
Set wrdApp = Nothing
End Sub

ªì¾ÇªÌ±`±`·|©¿²¤³Ì«á¨â¥y¡A¦pªG¤£¼gÁöµM¤£·|¼vÅTµ{¦¡ªº¹B¦æ¡A¦ý±q°O¾ÐÅéºÞ²z©M®Ä¯à±±¨îªº¨¤«×¦Ó¨¥¡A³o¬O­Ó«Ü¤£¦nªº²ßºD¡C


¦A½Ð±Ð«e½ú ¦pªG¦³«Ü¦hª«¥óÅÜ¼Æ ¥i¥H¤@¦¸²MªÅ¥¦­Ì¶Ü?
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

«õ¶ë ¡A¾Ç¤FVBA¨â¤T¦~¤F¡A²{¦b¤~¬Ý¨ì³o½g¡A
¤Ó·PÁ¤F!!!
³o½g¯uªº«D±`ªº»Ý­nªü

TOP

·PÁªO¥D¤À¨É:
³o¬O¤@½g¦n¤å³¹¡A¹ï©óªì¾ÇªÌªº§Ú¦Ó¨¥¦³«Ü¤jªºÀ°§U

TOP

¾Ç²ß¤¤¡AÁÂÁ¤j¤j

TOP

·PÁª©¥Dªº¤À¨É¡AÀò¯q¨}¦h

TOP

¦^´_ 1# Hsieh

°O±o¤§«e¦b®Ñ¤W¬Ý¨ì¡A"."ªº¼Æ¶q¤]¬O¶V¤Ö¶V¦n¡A©Ò¥H¤]À³¸Ó¦h¨Ï¥Îwith³¯­z¦¡¥H¤ÎÂÇ¥Ñsetª«¥óÅܼƪº¤è¦¡´î¤Ö"."ªº¨Ï¥Î
Excel VBAºô­¶¸ê®Æ¦¬¶°±Ð¾Ç:
http://forum.twbts.com/thread-20848-1-1.html

TOP

¨ü±Ð¤F!ÁÂÁª©¥D¤À¨É!

TOP

·PÁª©¥Dªº¤À¨É¡AÀò¯q¨}¦h
¸`¬Ù·s¤â«Ü¦hªº®É¶¡¤]°ö¾i¨}¦nªº²ßºD

TOP

ª©¤j¦³±ÀÂˬƻò®Ñ¥i¥H¥hŪªº¶Ü

¹ï·s¤â¨Ó»¡

TOP

        ÀR«ä¦Û¦b : ¯à·F¤£·F¡A¤£¦p­W·F¹ê·F¡C
ªð¦^¦Cªí ¤W¤@¥DÃD