![]() |
#1
|
|||
|
|||
![]() Hi to all, I'm looking for a short and reliable way to determine if the current selection is within a Word table or a "{ LINK Excel.Sheet ... }" Excel table. Selection.Information in both cases is wdWithinTable. .Parent in both cases is the current document. .Creator and .Application in both cases is Word. So where is the difference? Thanks for any help NP |
#2
|
||||
|
||||
![]()
What you really need to do here is to determine whether the selection is within a field. The following function does that.
Code:
Function WithInField(Rng As Word.Range) As Boolean ' Based on code by Don Wells: http://www.eileenslounge.com/viewtopic.php?f=30&t=6622 ' Approach : This procedure is based on the observation that, irrespective of _ a field's ShowCodes state, toggling the field's ShowCodes state _ twice collapses the selection to the start of the field. Dim lngPosStart As Long, lngPosEnd As Long, StrNot As String WithInField = True Rng.Select lngPosStart = Selection.Start lngPosEnd = Selection.End With Selection .Fields.ToggleShowCodes .Fields.ToggleShowCodes ' Test whether the selection has moved; if not, it may already have been _ at the start of a field, in which case, move right and test again. If .Start = lngPosStart Then .MoveRight .Fields.ToggleShowCodes .Fields.ToggleShowCodes If .Start = lngPosStart + 1 Then WithInField = False End If End If End With End Function Code:
Sub TestWithInField() Dim Rng As Word.Range, c As Word.Range, StrRslt As String Set Rng = Selection.Range For Each c In Rng.Characters StrRslt = StrRslt & c.Text & ",WithInField:" & WithInField(Rng:=c) & vbCr Next Rng.Select MsgBox StrRslt End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Hi Paul,
thanks for your answer. It is excactly as I feared: I need 'field testing'. So no real "short way" ... I will use your (almost) ready to use code ![]() Have a nice day NP |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Selection or Range | Tommes93 | Word VBA | 1 | 04-10-2014 02:50 AM |
![]() |
ramsgarla | Word VBA | 9 | 12-05-2012 03:23 AM |
![]() |
tinfanide | Word VBA | 3 | 04-27-2012 09:48 AM |
![]() |
tinfanide | Word VBA | 1 | 02-06-2012 05:57 AM |
![]() |
cs_starter | Mail Merge | 2 | 09-08-2011 02:58 AM |