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

¤Á´«¤u§@ªí«áµLªk§ó·s³Q½Æ»sÀx¦s®æ¸ê®Æ

¤Á´«¤u§@ªí«áµLªk§ó·s³Q½Æ»sÀx¦s®æ¸ê®Æ

§Ú¦b Sheet1 ±µ¦¬ DDE ³ø»ù¸ê®Æ»P³]©wÅã¥Ü¹Ïªí¡AµM«á¼g VBA µ{¦¡¡A©T©w¨C 30 ¬í¦b Sheet2 ¬ö¿ý±q DDE ©Ò±µ¦¬ªºÅܰʸê®Æ¡C

§Úªº°ÝÃD¬O¡A·í¤Á´«¨ì Sheet2 ¤u§@ªí®É¡A¾ã­Ó¹BÂà¤@¤Á¥¿±`¡F¦ý¬O­Y·í§Ú¤Á´«¨ì Sheet1 ®É·QÆ[¬Ý¹Ïªíªº§Y®ÉÅã¥Ü¡ASheet2 ¤ºªº¬ö¿ý´N·|°±¤î¡A°£«D¦A¤Á´«¦Ü Sheet2 ¤u§@ªí¡A¤~¤S·|©w®É¬ö¿ý¡C

§Úªº VBA µ{¦¡¦p¤U¡G
-------------------------------------------------------------
Option Explicit
Public nRow, Pos As Integer

Private Sub Workbook_Open()
    On Error Resume Next
    'Application.OnTime TimeValue("08:43:00"), "ThisWorkBook.SyncData"
    Call SyncData
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
    Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.SyncData", , False
End Sub

'*****************************************************************************
'   ±N DDE §Y®É³ø»ù¸ê®Æ¨Ì®É¶¡¶¡¹j¼g¤J¦Ü³ø»ù¸ê®Æ°Ï
'*****************************************************************************
Public Sub SyncData()
      
    On Error Resume Next
    'If TimeValue(Now) > TimeValue("13:46:00") Then Exit Sub
   
    With .Sheets("§Y®É¸ê®Æ")
        nRow = .Range("A65536").End(xlUp).Row '§PÂ_³Ì«á¤@¦C¦³¸ê®Æªº¦ì¸m
                             
        Pos = nRow + 1
               
        Cells(Pos, 1) = Time
        Cells(Pos, 3) = Sheets("DDE³ø»ù").Cells(7, 3)  '¥x«ü´Á¦¨¥æ»ù
        
    End With
   
    Application.OnTime Now + TimeValue("00:00:30"), "ThisWorkBook.SyncData"  '¨C¹j©T©w³]©w®É¶¡°õ¦æ¼g¤J¦Ü§Y®É¸ê®Æªí
End Sub
-----------------------------------------------------------------------------

§Úªº VBA µ{¦¡¬O¼g¦b "ThisWorkBook" ¤º¡C

½Ð°Ý¡G
1. µ{¦¡¤º­þ¸Ì¦³°ÝÃD¡H ¦Ó¾É­P¤Á´«¨ì¨ä¥¦¤u§@ªí«á´N°±¤î¬ö¿ý¡C
2. ¨ì©³³oµ{¦¡ (SyncData) ¬O§_¼g¦b ThisWorkBook ÁÙ¬O Module ¤º¤ñ¸û²z·Q©O¡H §Ú¤@ª½·d¤£¤ÓÀ´ ThisWorkBook »P Module ªº®t§O¡C

¦Û°Ý¦Ûµª¤@¤U¡C

¥Ø«e§Ú¬O¨Ï¥Î Sheet2.Activate ¨Ó¸Ñ¨M¡C¦ý³o¼Ë¦³¨Ç°ÝÃD¡A¦pªG§A·QÀH®ÉÆ[¬Ý¹Ïªí®É (Sheet1)¡AVBA µ{¦¡·í¹J¨ì Sheet2.Activate ´N·|¤Á´«¨ì Sheet2 ¤u§@ªí¡C

©Ò¥H¥u¦n·í¤Á¦^ Sheet2 ³B²z§¹Àx¦s®æªº½Æ»s®É¡A¦A¨Ì¾Ú­ì¨Ó©Ò¦bªº¤u§@ªí¡A¨ú±o¦WºÙ«á¡A¦A¤U«ü¥O¤Á¦^¥h¡C³o¼Ëªº«á¿ò¯g¬Oµe­±±`·|°{°Ê¤@¤U (¦]¬°¤Á¨ì Sheet2 ¤S¤Á¦^ Sheet1)¡C
³B²zªºÅÞ¿è¬O³o¼Ë¡G
name = ThisWorkbook.ActiveSheet.Name
Sheet2.Select
......
......
......
ThisWorkbook.Sheets(name).Activate

¤£ª¾¹Dª©¤W¦³¸gÅ窺¤j¤j­Ì¬O§_¦³§ó¨Îªº¸Ñ¨M¤è®×¡H

TOP

¦^´_ 2# gnimnek168


    .Cells(Pos, 1) = Time
    .Cells(Pos, 3) = Sheets("DDE³ø»ù").Cells(7, 3)
¬O¼g¤J§Y®É¸ê®Æ¤u§@ªí¶Ü?
with°Ï¬q¤º­n¥[¤J.
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_  gnimnek168
    .Cells(Pos, 1) = Time
    .Cells(Pos, 3) = Sheets("DDE³ø»ù").Cells(7, 3)
¬O¼g¤J§Y®É¸ê®Æ¤u§@ªí¶Ü?
with°Ï¬q¤º­n¥[¤J.


¤£¦n·N«ä¡A¤£¤F¸Ñ±zªº»¡©ú¡H

¤W­z¨â­Ó Cell Àx¦s®æ¬O¦b "§Y®É¸ê®Æ" ¤u§@ªí (sheet2) ¨S¿ù¡C

TOP

¦^´_ 4# gnimnek168


    ´N¦]¬°§A­n¼g¤Jªº¦ì¸m¦b§Y®É¸ê®Æ¤u§@ªí
©Ò¥H¥²¶·«ü¦W¤u§@ªí¡A¦b¤Á´«¤u§@ªí®É¤~¤£·|³y¦¨»~§P
¦]¬°¦bTHISWORKBOOK»P¤@¯ë¼Ò²Õ¤º¡A¥¼«ü©w¤u§@ªí¦WºÙ·|³Q»{©w¬°§@¥Î¤¤¤u§@ªí
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¥»©«³Ì«á¥Ñ gnimnek168 ©ó 2011-12-15 23:55 ½s¿è
¦^´_  gnimnek168
´N¦]¬°§A­n¼g¤Jªº¦ì¸m¦b§Y®É¸ê®Æ¤u§@ªí
©Ò¥H¥²¶·«ü¦W¤u§@ªí¡A¦b¤Á´«¤u§@ªí®É¤~ ...
Hsieh µoªí©ó 2011-12-15 17:28


½Ð°Ý³o­Ó¡GWith .Sheets("§Y®É¸ê®Æ")¡A¤£¬O¤w¸g¦³«ü©w¤u§@ªí¦WºÙ¤F¶Ü¡H

==============================================
°Ú°Ú¡A§ÚÁA¸Ñ¤j¤jªº·N«ä¤F¡A­ì¨Ó´N¬O CELL() «e­±­n¥[¤W .CELL¡C

«¢¡A»°ºò¨Ó¸Õ¸Õ¬Ý¡A·PÁ·PÁ¡C ^^

TOP

        ÀR«ä¦Û¦b : ¤£©È¨Æ¦h¡A¥u©È¦h¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD