Slowing Down a Macro

kbdavis11

New Member
Joined
Dec 8, 2014
Messages
30
I would have never thought I would ask this in my entire time while using macros, but I just cannot figure out the issue and I need to use this macro before I can try to debug it. In the meantime, I just need it to s...l...o...w........d....o....w....n..... if you get that hint.

Here's the thing, I have tried sleep commands and application.wait commands in strategic spots with no resolution. The text is not copying to the clipboard as I hoped while going at full speed. I have even attempted to loop some things to see if it would catch the 2nd, 3rd, 4th, to the 50th time, no luck. It's obviously my clipboard function I am using, but as I said, no time to debug.

Anyways, here's my code for now. While I am not necessarily asking for code improvements, I am not objecting to them either on a different clipboard handling solution. I know everything works in slow-mo, as when I run the macro line-by-line, it works flawlessly (for my limited testing).

Code:
#If VBA7 Then ' Excel 2010 or later

    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)


#Else ' Excel 2007 or earlier


    Private Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)


#End If


Dim ATC As AccuTermClasses.AccuTerm


Sub Auto_Client()
    
    Set ATC = GetObject(, "ATWin32.AccuTerm")
    
    ' Clipboard stuff..
        Dim MyData As MSForms.DataObject
        Set MyData = New MSForms.DataObject
        MyData.GetFromClipboard
        
        Dim sClipText As String
        ' Get data from the clipboard.
        ' use these for cb: 1.) MyData.GetFromClipboard
        '                   2.) sClipText = MyData.GetText(1)


    Dim E As String
        E = Chr$(13)
    Dim LFT As Integer
    Dim RT As Integer
    Dim RW As Integer
    Dim CLT As String
    Dim Prmt As String
    Dim CountCLT As Integer
    Dim MBoxResp As Integer
    Dim AcctNmbr As Integer     ' used to check to see if CM will popup or not.. Gotta love it!
    Dim Counter As Integer      ' Loop counter (preventing infinate loops)
        Counter = 0
    
    LFT = 56        ' Left side of name
    RT = LFT + 5    ' Do NOT change, relative to LFT
    RW = 0          ' Row number (-1)
    
'   Just ignore these. What may look like incomplete strings to the outside world work for what I need....
    Dim PPlan As String
        PPlan = "on pplan"
    Dim Deact As String
        Deact = "Deactivate Payment"
    Dim Wrning As String
        Wrning = "been Take"
    Dim FutTran As String
        FutTran = "on Future Transaction "
    Dim AddTick As String
        AddTick = "ickler? (Y,CR=N,C)"
    Dim CM As String
        CM = "PRESS ENTER TO CONTINUE"
        
    Do
        ActiveCell.Offset(1, 0).Select
        Do Until ActiveCell.Height <> 0
        ActiveCell.Offset(1, 0).Select
        Loop
        If ActiveCell.Offset(0, 1) < 1000000 Then
            Exit Sub
        Else
            ActiveCell.Offset(0, 1).Copy
            
                    ' Grabbing clipboard contents for cm check..
                    MyData.GetText (1)
                    Sleep 150
                    MyData.GetFromClipboard
                    sClipText = MyData.GetText(1)
                    sClipText = RIGHT(sClipText, Len(sClipText) - 6)
                    AcctNmbr = CInt(sClipText)
                    'MsgBox AcctNmbr
                                        
            With ATC.ActiveSession
                .InputMode = 0
                .Paste ""
                If AcctNmbr = 5 Then
                    Sleep 1250
                    .Output E
                    Sleep 150
                End If
                
                Sleep 150
                
                    'checking for random prompts...
                    .SetSelection 8, 23, 36, 23
                    .Copy 8, 23, 36, 23
                    MyData.GetFromClipboard
                    sClipText = MyData.GetText(1)
                    sClipText = Left(sClipText, Len(sClipText) - 2)
                    Do
                    If sClipText = PPlan Then
                        .Output "N" + E
                        Sleep 100
                    ElseIf sClipText = Deact Then
                        .Output "C" + E
                        Sleep 100
                    ElseIf sClipText = Wrning Then
                        .Output E
                        Sleep 100
                    ElseIf sClipText = FutTran Then
                        .Output E
                        Sleep 100
                    ElseIf sClipText = AddTick Then
                        .Output "C" + E
                        Sleep 100
                    End If
                    Sleep 100
                    .Copy 8, 23, 36, 23
                    Sleep 100
                    .WaitFor 0, 1, "1HCMD"
                    MyData.GetFromClipboard
                    sClipText = MyData.GetText(1)
                    sClipText = Left(sClipText, Len(sClipText) - 2)
                    Loop Until (sClipText <> AddTick And sClipText <> FutTran And sClipText <> PPlan And sClipText <> Deact And sClipText <> Wrning)


                .WaitFor 0, 1, "1HCMD (/,?): "
                Application.CutCopyMode = False
                
                Do While (Counter < 50 And CountCLT <> 6)
                Counter = Counter + 1
                Application.Wait (Now + TimeValue("00:00:01"))
                .Copy LFT, RW, RT, RW
                Application.Wait (Now + TimeValue("00:00:01"))
                MyData.GetFromClipboard
                sClipText = MyData.GetText(1)
                Application.Wait (Now + TimeValue("00:00:01"))
                CLT = Left(sClipText, Len(sClipText) - 2)
                CountCLT = Len(CLT)
                If CountCLT = 6 Then
                    GoTo passed
                End If
                Loop
passed:
                If Counter = 50 Then
                    MsgBox CLT & ", which is #" & CountCLT & E & E & "Could not get client code. Operation aborted!", vbCritical, "Infinate Loop Warning"
                    Exit Sub
                End If
                Counter = 0
                .Output "/" + E
                .InputMode = 0
                Sleep 50
                .ClearSelection
            End With
                Sleep 50
                ' Assign clipboard contents to string variable sClipText.
            Dim TST As Integer
            'TST = MsgBox(CLT + "|", vbOKCancel)
                If TST = vbCancel Then
                    Exit Sub
                End If
            ActiveCell.Value = CLT
        End If
    Loop




End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Have you tried putting break points in your code and/or run the code step-by-step (F8)?
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,348
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top