Hi all!
Is there a way to check via vba if a guideline exist at a specific coordinate?
I ask this because I made a macro wich creates guidelines for multiple objects and many guides appear as duplicates.
I want the macro to check if a guide allready exist, and only if not, to create it.
Thank you very much.
You could use CQL to search for guidelines that meet certain criteria.
I put this together fairly quickly, and haven't put any time into polishing it, but it might give you some ideas.
The sub that tests it is looking for horizontal guidelines located at a Y position of 1.234, with a tolerance of 0.01. It reports the count of matching guides. If the count is greater than zero, then it selects those guides.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Sub test_check_page_for_horiz_guide() Dim sr_matching As ShapeRange check_page_for_horiz_guide_at_Y_position ActivePage, 1.234, 0.01, sr_matching MsgBox "Number of matching guides: " & sr_matching.Count If sr_matching.Count > 0 Then sr_matching.CreateSelection Else ActiveDocument.ClearSelection End If End Sub '------------------------------------------------------------------------------------ Function check_page_for_horiz_guide_at_Y_position(ByVal TargetPage As Page, ByVal YPosition As Double, ByVal Tolerance As Double, Optional ByRef MatchingGuideShapes As ShapeRange) As Boolean Dim srR As ShapeRange Set sr = TargetPage.Shapes.FindShapes(query:="@type='guideline' And @com.guide.type = " & cdrHorizontalGuide & " and (" & YPosition & "-@com.centerY).abs <= " & Tolerance) Set MatchingGuideShapes = sr If sr.Count > 0 Then check_page_for_horiz_guide_at_Y_position = True End If End Function
Something like this I've tryed myself but without tolerance, and some guide was not finded. I'll try your idea.
sorin12003 said:Something like this I've tryed myself but without tolerance, and some guide was not finded. I'll try your idea.
I have learned - by trying and failing - to use a tolerance for such comparisons!