Results 1 to 13 of 13
  1. #1
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Runtime error (2002)

    I'm getting "Run-time error 1004", Application-defined or Object-defined error on the line:

    pcommPS.SetText Worksheets("CERTEGY KEYING SHEET").Range(Cells(intStart, 2), Cells(intStop, 9)), 2, 11

    Any idea's?

    Dim n As Integer
    Dim intStart As Integer
    Dim intStop As Integer
    Dim i As Integer

    For n = 1 To 250
    intStart = 12 * n + 9
    If Worksheets("CERTEGY KEYING SHEET").Cells(intStart, 2) = "" Then
    Exit For
    Else
    intStop = intStart
    For i = 1 To 3
    If Worksheets("CERTEGY KEYING SHEET").Cells(intStart + 3 * i, 2) = "" Then
    Exit For
    Else
    intStop = intStop + 3
    End If
    Next i
    pcommPS.SetText Worksheets("CERTEGY KEYING SHEET").Range(Cells(intStart, 2), Cells(intStop, 9)), 2, 11
    pcommOIA.WaitForAppAvailable 5
    pcommOIA.WaitForInputReady
    pcommPS.SendKeys "[Enter]"
    pcommOIA.WaitForAppAvailable 5
    pcommOIA.WaitForInputReady
    pcommPS.SendKeys "[Enter]"
    pcommOIA.WaitForAppAvailable 5
    pcommOIA.WaitForInputReady
    End If
    Next n

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Runtime error (2002)

    Same answer as to your previous question: you have change Cells(...) to Worksheets("CERTEGY KEYING SHEET").Cells(...)

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Runtime error (2002)

    It'll make your life easier if you use a worksheet variable too:
    <pre> Dim n As Integer
    Dim intStart As Integer
    Dim intStop As Integer
    Dim i As Integer
    Dim wks As Worksheet
    Set wks = Worksheets("CERTEGY KEYING SHEET")
    For n = 1 To 250
    intStart = 12 * n + 9
    If wks.Cells(intStart, 2) = "" Then
    Exit For
    Else
    intStop = intStart
    For i = 1 To 3
    If wks.Cells(intStart + 3 * i, 2) = "" Then
    Exit For
    Else
    intStop = intStop + 3
    End If
    Next i
    pcommPS.SetText wks.Range(wks.Cells(intStart, 2), wks.Cells(intStop, 9)), 2, 11
    pcommOIA.WaitForAppAvailable 5
    pcommOIA.WaitForInputReady
    pcommPS.SendKeys "[Enter]"
    pcommOIA.WaitForAppAvailable 5
    pcommOIA.WaitForInputReady
    pcommPS.SendKeys "[Enter]"
    pcommOIA.WaitForAppAvailable 5
    pcommOIA.WaitForInputReady
    End If
    Next n
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error (2002)

    Thanks both. I copied from Rory's response and now I get error 13, type mismatch on the same line.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Runtime error (2002)

    Can you use SetText with a range consisting of multiple cells?

  6. #6
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error (2002)

    <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23> I fear not. Then I must find another way....

  7. #7
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error (2002)

    Never one to give up............
    I've searched and searched the web for assistance these last few weeks, but there is such little information readily available. I know that this is not strictly on topic, but I appreciate all the advice that is given.

    The best resource that I have found to date >> Personal Communications (PCOMM) terminal emulator
    <hr>The GetText method will only read a single screen row. Display fields that wrap over more than one line will need special attention. GetTextRect (Get Text Rectangle) may be a better method to use for this case.<hr>
    So I wonder, would the same apply to the SetText method? e.g.

    pcommPS.SetTextRect wks.Range(wks.Cells(intStart, 2), wks.Cells(intStop, 9)), 2, 11

    Hopefully!! If that fails, I will need to change the loop to SetText for 20 individual items (4 rows of 5).

    Thoughts??

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Runtime error (2002)

    > Thoughts??

    No, I don't have this software. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  9. #9
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error (2002)

    OK, SetTextRect is not an option. So, I think (in the attached), I need to change the row numbers (21, 24, 27, 30) for i?? But am not sure?
    Attached Files Attached Files

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Runtime error (2002)

    Change

    pcommPS.SetText wks.Range("B21"), 9, 6

    to

    pcommPS.SetText wks.Range("B" & intStart), 9, 6

    Similarly, change

    pcommPS.SetText wks.Range("B24"), 12, 6

    to

    pcommPS.SetText wks.Range("B" & (intStart + 3)), 12, 6

    etc. etc. etc.

  11. #11
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error (2002)

    Many Thanks Hans, nearly at the finish line, but I have one (hopefully) final issue.

    pcommPS.SetText wks.Range("F" & intStart), 9, 37

    ("F" & intStart) is a formula that picks up a date from another sheet. The date is formatted to custom ddmmyy, the cell shows 221108. If I copy the cell into word, the result is as expected 221108.

    The coordinates (Row 9, column 37) is a string of 6, expecting 221108. However, it picks up "22/11/" which causes a failure.

    I am thinking that the way to go is to use "left, mid, right", but I am not sure of how to put that together. Unless there are any other suggestions?

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Runtime error (2002)

    Use

    pcommPS.SetText wks.Range("F" & intStart).Text, 9, 37

    The .Text property of a cell is the value as formatted and displayed on screen.

  13. #13
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error (2002)

    Great! Thanks, hopefully that will be project complete!!

Posting Permissions

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