Results 1 to 20 of 22

Thread: Is it possible to loop a macro constantly?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Is it possible to loop a macro constantly?

    Hi, I am wondering whether it is possible to make a macro loop constantly while a spreadsheet is open? Or even better, to loop constantly whenever the mouse click button is being held down?

    I have some macros which read the information from a text file and input the data into the workbook, but i need to get it to do it constantly, because the data in the text file is changing because I am writing to it from max msp.

    At the moment you click the button to read the text file but i need it to read the file whenever the mouse buttno is held down, not just clicked, because as i click the button and drag the mouse the text file data will be changing so i need the spreadsheet to continually update itself.

    is that possible?

    The code i have is below

    MODULE 1

    [VBA]
    Option Explicit

    Dim myDB As clsADODBopen

    Sub Main()
    Dim strCmn As String
    Dim FN As String
    FN = "testing.txt"
    Set myDB = New clsADODBopen
    strCmn = "select * from " & FN
    With myDB
    .subConn ThisWorkbook.Path & "\"
    .subOpen strCmn
    End With
    subShow
    Set myDB = Nothing
    End Sub

    Sub subShow()
    Dim i As Integer, c As Long
    Dim pt As Range

    Set pt = ActiveSheet.Range("a1")
    pt.Worksheet.Cells.ClearContents
    c = 0
    With myDB.theRST
    For i = 1 To .Fields.Count
    If c = pt.Worksheet.Cells.Columns.Count Then
    c = 0
    Set pt = pt.Offset(1, 0)
    End If
    pt.Offset(0, c).Value = .Fields(i - 1).Name
    c = c + 1
    Next
    'pt.Offset(1, 0).CopyFromRecordset myDB.theRST
    End With
    End Sub

    MODULE 2
    Option Explicit

    Dim theCON As ADODB.Connection
    Public theRST As ADODB.Recordset


    Sub subConn(strFullName As String)
    Dim strDrv As String

    strDrv = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
    " DBQ=" & strFullName & ";"
    theCON.Open "Provider=MSDASQL; " & strDrv
    End Sub


    Sub subOpen(strCmn As String)
    theRST.Open Source:=strCmn, ActiveConnection:=theCON
    End Sub


    Private Sub Class_Initialize()
    Set theCON = New ADODB.Connection
    Set theRST = New ADODB.Recordset
    End Sub


    Private Sub Class_Terminate()
    theCON.Close
    Set theRST = Nothing
    Set theCON = Nothing
    End Sub
    [/VBA]

    thanks in advance for your help!
    Last edited by mdmackillop; 04-08-2009 at 05:37 AM. Reason: typo error in title

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •