none
sendkeys not working in some modules RRS feed

  • Question

  • I need to cut and paste equations in to active document.    
        Sub sample()
            Dim eqns As omath
            Dim objData As New MSForms.dataobject
            Dim strText As String
            For Each eqns In ActiveDocument.OMaths
                eqns.Range.Select
                Selection.Cut
                objData.GetFromClipboard
                strText = objData.GetText()
                objData.SetText strText
                objData.PutInClipboard
                SendKeys ("^v") ''This sendkey paste only v
            Next
        end sub
    
    When I try to paste string which is in clipboard, it pastes only "v"
    If I have seperate module for sendkey, then it pastes fine.
    sub samplepaste()
        sendkeys("^v")  ''IT pastes fine
    end sub
       Even I tried to call these modules in a module like,    
    sub samplemaster()
           call sample
           call samplepaste
    end sub
    When these two modules combined, again sendkeys("^v") pastes only "v"

    To get my requirement, I should run both of these modules seperately. It is not needed. I couldn't make `sendkeys` work in first module itself. What is the problem here?
    Wednesday, January 11, 2017 12:35 PM

All replies

  • Hi,

    What is your specific version of Office? How do you run the macro?

    The code works for me. It would get all the equations from the document and paste into one.

    Besides, if I run the two modules separately or call them in one Sub, it should get the same result: paste the last equation.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 13, 2017 5:51 AM
    Moderator
  • Hi,

       Actually my objective is converting equation editor equations to mathtype equations.

    So I did, 

    1.In equation editor tools, selected "copy and paste preferences as mathml"

    2. In mathtype settings, selected "paste preference as mathytype (mathml to mathtype)"

    Now If i cut equation editor equations and paste it in that place, I will get mathtype equation. When I cut equation editor equation, clipboard will have mathml content. When I paste it, It will be converted to mathtype equation. If I do it manually, it works. 

    So I created first module to cut equation editor and clipboard will have mathml content. If I do "ctrl+v" manually, it pastes fine (mathtype equation). When I try selection.paste, I don't get mathtype equation. So I tried sendkeys("^v"), but this pastes only word "v". If I have sendkey module seperately everything works fine.

    So now am doing like, run these two modules seperately. Why sendkeys not working in the middle of macro?

    Friday, January 13, 2017 6:25 AM
  • Hi,

    What is your specific version of Office? Could you please share a sample file with us to test?

    Let us check if the issue causes from the file or the environment.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 17, 2017 6:50 AM
    Moderator