Jump to content

Microsoft Office VBA Editor IDE Ctrl-Y Redo


Recommended Posts

Excel VBA's IDE registers a Control-y as "cut this line of code".

For those prone to Undo/Redo (Ctrl+Z/Ctrl+Y) you may find frustration when your code in the editor does not redo, but in fact clears your active line of code while killing redo history.

Though not perfect, I keep this tool running in background on startup.

The purpose is to allow Cltr+Y to act normally throughout Windows and Office and only interact *differently* with the "Microsoft Visual Basic for Applications" window that is active.

If the Standard Menu bar exists, it'll try to click the ReDo (Blue Arrow to the right), else "Alt+e, r" keystrokes (less desired).

 

Here's the code:

Opt('MustDeclareVars', 1)
Opt("WinTitleMatchMode", 1)

HotKeySet("^y", "TriggerRedo")

While 1
    Sleep(10)
WEnd

Func TriggerRedo()
    ConsoleWrite("TriggerRedo()" & @CRLF)
    Local $title = "Microsoft Visual Basic for Applications - "
    Local $hWnd
    If WinExists($title) And WinActive($title) Then
;~      Parent Window Handle
        $hWnd = WinGetHandle($title)
        Local $aWindowPos = WinGetPos($hWnd)
;~      Control Bar Handle, Position and If Visible
        Local $sControlID = "[CLASS:MsoCommandBar; TEXT:Standard;]"
        Local $hStandardBar = ControlGetHandle($hWnd, "", $sControlID)
        Local $bIsVisible = ControlCommand($hWnd, "", $sControlID, "IsVisible")

        If $hStandardBar And $bIsVisible Then
            ConsoleWrite("Using Mouse Click." & @CRLF)
;~          Determine Redo button location on visible Control Bar
            Local $aBarPos = ControlGetPos($hWnd, "", $sControlID)
            Local $mX = $aWindowPos[0] + $aBarPos[0] + 217 + Int(23/2)
            Local $mY = $aWindowPos[1] + $aBarPos[1] + 27 + Int(22/2)
            MouseClick("Left", $mX, $mY, 1, 0)
        Else
            ConsoleWrite("Using VBA Send Keys." & @CRLF)
            $sControlID = "[CLASS:MsoCommandBar; TEXT:Menu Bar;]"
            Local $hMenuBar = ControlGetHandle($hWnd, "", $sControlID)
            ControlSend($hWnd, "", $hMenuBar, "!e")
;~          Send("r")
            $sControlID = "[CLASS:MsoCommandBarPopup; TEXT:Edit;]"
            Local $hPopupBar = ControlGetHandle($hWnd, "", $sControlID)
            ControlSend($hWnd, "", $hPopupBar, "r")
        EndIf
    Else
        ConsoleWrite("Using NATIVE Send Keys." & @CRLF)
        HotKeySet("^y")
        Send("^y") ;~ may cause "yyy..." when held
        HotKeySet("^y", "TriggerRedo")
    EndIf
EndFunc   ;==>TriggerRedo

Hope this inspires someone.

 

 

Edited by Page2PagePro
Type-o
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By goku200
      I have an Autoit script that lists files from a folder into an array list. Is there a way to separate the filenames by an underscore and include the id, version, name and date into separate columns in Excel.
      Example of filename:
      12345_v1.0_TEST Name [12345]_01.01.2022.html
      12345 would be in one column
      v1.0 would be in another column
      TEST Name [12345] would be in another column
      01.01.2022 would be in another column
      .html would be in another column
      Note: filenames always change each day.
      Here is my code that lists the files into column C and then writes the column Headers into Column D, E, F, G. Just need some help with separating them into columns by the _ delimiter
       
    • By SkysLastChance
      I am having a issue of whenever I try to _Excel_RangeWrite a formula that references another workbook I am getting an error @4 and @extended -2147352567

      #include <Excel.au3> #include <MsgBoxConstants.au3> Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookNew($oExcel) _Excel_RangeWrite($oWorkBook,Default,"=IF(D2=D1,"",VLOOKUP(D2,'J:\Temporary Files\FolderName\FileName.xlsx'!$A:$B,2,0))","W2",False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "String successfully written.") I am not a 100% sure, but I am guessing this is because I have "" and '' in the formula. However, I am not sure how this can best be resolved. 
       
       
    • By SkysLastChance
      I am trying to autofill a range. I am getting stuck and I don't understand what I am doing wrong. 
      My goal is to auto fill some formulas that are next to a pivot table in columns A-C. 
      _Excel_RangeWrite($oNewWorkBook,Default,"2000","D3") _Excel_RangeWrite($oNewWorkBook,Default,"=(B3-D3)","E3") _Excel_RangeWrite($oNewWorkBook,Default,"100","F3") _Excel_RangeWrite($oNewWorkBook,Default,"=(C3-F3)","G3") $oNewWorkbook.ActiveSheet.Range("D3:G3").Select With $oNewWorkbook .Selection.AutoFill(.Range("D3:G77"),0) EndWith The data is not auto filling. 
      Hoping someone can point me in the right direction. 
    • By Rskm
      Hi, I have 5 notepad files with lot of data in each of it. The data are arranged in lines and i wish to get it pasted/copied into excel.  Say, i need to read notepad1 and paste the contents into sheet1 of excel and notepad2 to sheet2 and so on.  If i read the notepad and paste it line by line, it is taking lot of time.  Is there a way by which i can paste the whole of notepad file into excel sheet(and get it pasted line by line as shown in the attached excel), instead of using code to write it line by line?.. I was using Filewriteline(data, line i) initially to write to excel.  The 'i' value was incremented with for loop and the excel was updated, but this takes lot of time.  The expected excel format is attached here.  any help is appreciated.  thanks
      Tmp.xls
    • By water
      Extensive library to control and manipulate Microsoft Outlook. This UDF holds the functions to automate items (folders, mails, contacts ...) in the background. Can be seen like an API.
      There are other UDFs available to automate Outlook:
      OutlookEX_GUI: This UDF holds the functions to automate the Outlook GUI. OutlookTools: Allows to import/export contacts and events to VCF/ICS files and much more.  Threads: Development - General Help & Support - Example Scripts - Wiki
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2020-02-09)
      None
×
×
  • Create New...