PDA

View Full Version : Assign Marco to Text Box



Rosanna24
08-06-2019, 11:21 PM
Hi,
Can anyone help with something that looks like it should be really simple but I can’t see how to do it. I have a simple Marco that sorts a table by date. It runs fine. I have put a text box in my document ‘sort by date’ but can’t work out how to link the existing Marco to the text box ? I’ve tried right click properties and assign code but it’s not very clear how to do this.
Thanks, if someone could tell me the easy way.
Rosanna

gmayor
08-07-2019, 02:52 AM
A text box? Surely what you want is a button, otherwise what is the relevance of the text box? You can call your macro from the button code. e.g.

Private Sub CommandButton1_Click() ActiveDocument.Tables(1).Sort _
ExcludeHeader:=False, _
FieldNumber:="Column 1", _
SortFieldType:=wdSortFieldDate, _
SortOrder:=wdSortOrderAscending
End Sub

Rosanna24
08-07-2019, 09:55 AM
OK thanks very much for this, I thought there might be an easier way.
thanks