Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2016, 07:03 AM
rocky2 rocky2 is offline How to find out if selection is in table Windows 10 How to find out if selection is in table Office 2013
Novice
How to find out if selection is in table
 
Join Date: Feb 2016
Posts: 25
rocky2 is on a distinguished road
Default How to find out if selection is in table

Hi,

I want to search for a certain style. I need to check if the selection is in a table, and if it is then in which row.



Because I search for the style, I have the selection and not the Paragraph.Range.

Is there any way to do that?

(Actually, what I really want to do is check for cells in which the font is white nd the background is white and then change the font to black. However, even though the paragraph style is correct, the font is set to automatic so when I search for white I don't get anything.)

Thanks,
Rocky
Reply With Quote
  #2  
Old 12-14-2016, 08:36 AM
gmayor's Avatar
gmayor gmayor is offline How to find out if selection is in table Windows 10 How to find out if selection is in table Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can get the table and row from the selection
Code:
Dim oTable As Table
Dim iRow As Long
If Selection.Information(wdWithInTable) Then
    Set oTable = Selection.Tables(1)
    iRow = Selection.Rows(1).Index
    MsgBox "Selection in row " & iRow
Else
    MsgBox "Not in Table"
End If
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-14-2016, 05:27 PM
macropod's Avatar
macropod macropod is offline How to find out if selection is in table Windows 7 64bit How to find out if selection is in table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rocky2 View Post
Because I search for the style, I have the selection and not the Paragraph.Range.
Word can give you either, so it's not necessary to work with a 'Selection' object. However, as you haven't posted your own code, we can't tell you how to make the appropriate modifications.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 12-15-2016, 03:10 AM
rocky2 rocky2 is offline How to find out if selection is in table Windows 10 How to find out if selection is in table Office 2013
Novice
How to find out if selection is in table
 
Join Date: Feb 2016
Posts: 25
rocky2 is on a distinguished road
Default

Thanks for your help!
It works
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find out if selection is in table Find if the selection is a horizontal line NevilleT Word VBA 4 06-26-2016 12:17 AM
How to find out if selection is in table Help required with Selection.Find to search a text file. Marko Word VBA 2 10-18-2014 06:32 AM
VBA to Find and Format Text string defined using Inputbox within selection sistemalan Word VBA 7 10-03-2014 07:28 AM
Excel 2013 Alt F doesn't block selection in find anymore KatMagic Excel 0 03-15-2014 12:44 PM
Automatic find replace after selection in dropdown vsempoux Word 0 10-28-2009 08:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:32 PM.


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