Consulting

Results 1 to 5 of 5

Thread: vba - Sendkeys Crtl+C and clipboard

  1. #1
    VBAX Newbie
    Joined
    Sep 2021
    Posts
    3
    Location

    vba - Sendkeys Crtl+C and clipboard

    hello, everybody.

    I need to test if a value stored in clipboard (got by Crtl+C) meet a certain condition. The macro is dependent ot that.

    But nothing ot I tried worked so far. I need help.
    The macro is for manipulate a java terminal emulator (IBM HOD)


    My current code is below. I reduced to better undertanding:

    Sub atucredor()
    
    
        Dim cpf As String
        Dim bco As String
        Dim ag As Integer
        Dim cta As Double
        Dim clipboard As String
        
    
    
        AppActivate "Terminal 3270 - A - AWVL6661"
        Application.Wait (Now + TimeValue("0:00:01"))
            
        For i = 2 To 2
            cpf = Worksheets("atucredor").Cells(i, 1)
            bco = Worksheets("atucredor").Cells(i, 3)
            ag = Worksheets("atucredor").Cells(i, 4)
            cta = Worksheets("atucredor").Cells(i, 5)
                
            Application.Wait (Now + TimeValue("0:00:01"))
            SendKeys cpf, True
            Application.Wait (Now + TimeValue("0:00:01"))
            SendKeys "{ENTER}", True
            Application.Wait (Now + TimeValue("0:00:01"))
            SendKeys "{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}", True
            Application.Wait (Now + TimeValue("0:00:01"))
            SendKeys "+{RIGHT}", True
            Application.Wait (Now + TimeValue("0:00:01"))
            clipboard = "^c"
            SendKeys clipboard, True
            Application.Wait (Now + TimeValue("0:00:02"))
            SendKeys "+{ESC}"
    
    
            If clipboard = "A" Then
    
    
            SendKeys "{F12}", True
            clipboard = ""
            Else
            Debug.Print clipboard
            End If
            Next

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    Here is a resource : https://www.mrexcel.com/board/thread...asting.889605/

    It is possible. First, go to the VBA Editor. In the menu, click on Tools --> References, then put a check next to Microsoft Forms 2.0 Object library. Then paste this code:


    ( Untested here )
    Sub PasteWOc()
    Dim MyText As String
    
        Set MyData = New DataObject
        MyData.GetFromClipboard
        MyText = MyData.GetText
    
        If Left(MyText, 2) <> "WO" Then Exit Sub
    
        Sheets("wo").Range("a1") = MyText
     End Sub


  3. #3
    IMHO, the OP code will definitely not work.
    you Activate the External prog, yes.
    But also use "worksheet", which will then shift focus to
    your Workbook/worksheet.

    you must first gather all info to the variable, then
    set focus on the external prog and do the Sendkeys.

    also, there are times that simple AppActive will not
    activate the app, you need to "find" the window handler
    of the app and put that window handler in the "foreground".

  4. #4
    VBAX Newbie
    Joined
    Sep 2021
    Posts
    3
    Location
    can I attach a videoscreen?

    I am trying attach a zip file and doesn't works.

    it's 9mb

  5. #5
    VBAX Newbie
    Joined
    Sep 2021
    Posts
    3
    Location
    maybe if I explain my objective, it's easiest to find a solution. I attached pictures.
    Basically, the macro is to register creditors in our system (very dated) that use the IBM Terminal). So, he get the data of first collumn (our id) and put inthe terminal (pic1). after it, there are two options:

    if thecreditor is already registered, the terminal open the window for change (see in the pic2_ ( A-ALTERACAOE-EXCLUSAO ) ). notice that (pic3) shift + right select the field of the cursor in second screen.

    that option is not what I want. only so, I use F12 in the macro to return to first screen (pic1) and get the second line of excel.
    if the creditor is not registered ( pic4, notice OPCAO : I - INCLUSAO), so, that macro proceeds to insert otherdata (other columns). but the field in that case is not empty (why? well, because the terminal pull the data from other database)

    I thought, ifI test the field after first screen, shift+right, crtl+c, variable (if = 0,it's the screen for change. if <> 0, its the screen for insert), I would find a solution.


    but maybe there are another form of test . could I test the position of cursor?? I don'tunderstant much of vba.

    pic1.jpgpic2.jpgpic3.jpgpic4.jpg

Posting Permissions

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