Click OK in a Message Box

Viewed 56

I have an Excel add-in "CData" and if I want to refresh the data a message box pops up for me to click OK or Cancel concerning overwriting the data. I want to create a macro that I can run that will click OK to the message box so I do not have to do it manually. I will have this as part of a larger Command Button. It will not work with Record a Macro under the View ribbon tab. When recording the macro I hit the keys Alt - S - R - A at this point the message box pops up and ask if I want to continue - with "OK" highlighted. I hit "Enter" and the file refreshes. I then hit Alt - W - M - R to stop recording the macro. This what I get.

Sub Macro4()
' Macro4 Macro
    Selection.ClearComments   
    ActiveWorkbook.Names.Add Name:="CDATA0", RefersToR1C1:= _
        "=TrialBalanceReport2022!R1C1:R2C26"
    ActiveSheet.ListObjects("TABLECDATA0").Resize Range("$A$1:$Z$2")
    Cells.Select
    ActiveSheet.ListObjects("TABLECDATA0").Resize Range("$A$1:$Z$102")
    Cells.Select
    ActiveSheet.ListObjects("TABLECDATA0").Resize Range("$A$1:$Z$1102")
    Cells.Select
    ActiveWorkbook.Names.Add Name:="CDATA0", RefersToR1C1:= _
        "=TrialBalanceReport2022!R1C1:R171C26"
    ActiveSheet.ListObjects("TABLECDATA0").Resize Range("$A$1:$Z$171")
    Cells.Select
End Sub

CDATA0 is the Heading. TABLECDATA0 is the Data. TrialBalanceReport2022 is the Worksheet name. Thanks for your help.

0 Answers
Related