Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2011, 11:27 PM
saslotteroy saslotteroy is offline Sort table using macro Windows 7 64bit Sort table using macro Office 2010 64bit
Novice
Sort table using macro
 
Join Date: Apr 2011
Posts: 7
saslotteroy is on a distinguished road
Default Sort table using macro

Hi

I have a table in word that I want to have sorted for a column by either clicking a button (text box in the document) or using the keyboard (i.e. CTRL + U). I have managed to do the latter; the table updates when hitting CTRL + U. This was done only by recording a macro. However the problem is that when recording I am chosing a table manually and when running the macro it depends where the cursor is placed (as there are several tables in the document)


So, my question is: is it possible to build into the macro that it's selecting the correct table? Maybe it is possible to give a table a title/name?

Also if there are other more elegant ways of doing this, I appreciate feedback on this.

Thank you!
Reply With Quote
  #2  
Old 09-15-2011, 04:39 AM
OTPM OTPM is offline Sort table using macro Windows 7 32bit Sort table using macro Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi
All tables, by default, are numbered in MS Word. For example the first table is Table1, the second Table2 etc.
So in your code you could put the following line of code before you sort your table:
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=3, Name:=""
This would take you to Table3 in the document.
Hope this helps.
Good luck.
Tony(OTPM)
Reply With Quote
  #3  
Old 09-15-2011, 02:41 PM
saslotteroy saslotteroy is offline Sort table using macro Windows 7 64bit Sort table using macro Office 2010 64bit
Novice
Sort table using macro
 
Join Date: Apr 2011
Posts: 7
saslotteroy is on a distinguished road
Default

Thanks.

This will help, however I there might be a problem if at a later stage adding a table above the one I have specified. The document where the macro is going to be added to is a template and will be used by a number of users not capable of updating any macros.
Is it possible to actually fix the name of the selected table?

Also another question; is it possible to add a macro to a "button" in the document. This could for instance be a text box like is possible in excel.

If nothing og the requested is possible I will probably go with the solution suggested. Thanks again!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort table using macro Generic range for custom sort macro? tswiers Excel Programming 2 08-11-2011 02:40 AM
Sort table using macro How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM
Can I sort a Pivot table by subtotals? oshkosh Excel 1 12-07-2010 06:20 PM
Sort Macros boutells Excel 1 07-16-2009 11:48 AM
Sort Range boutells Excel 1 07-15-2009 03:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2022 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft