Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2011, 01:08 PM
cksm4 cksm4 is offline Save Selection Windows XP Save Selection Office 2007
Advanced Beginner
Save Selection
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

Hello Paul,

This worked perfect! Thanks for guiding me towards a better solution and helping me with the proper code. It really helped me tremendously both in this project as well as learning more about VBA!

Brock
Reply With Quote
  #2  
Old 01-21-2011, 09:21 AM
cksm4 cksm4 is offline Save Selection Windows XP Save Selection Office 2007
Advanced Beginner
Save Selection
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

Hello Paul,

After much testing, I found that in order to have the users still user their prior forms created in Word 2002, I mush use the find method in my code as Word 2002 does not support rich text controls. I will have the user run a macro that will update the 2002 documents to include the necessary fields; however, they will not be controls. I created the below macro that first determines if there are controls, if yes then it’s a new form and I use the code you provided. If no, then it’s a prior version of the form and the code uses the find method. The problem I am having is that this is not working by section. The text found from the first section using the find method shows up on each section using the same method. When I read the code it appears to me that it is only running by sections… but somehow is it not stopping after each section. Any ideas? A big thanks for any insight you can provide!

Code:
 
Sub Demo()
 
Application.ScreenUpdating = False
Dim strTmp As String, oCel As Cell, rngTmp As Range, i As Integer, j As Integer
With ActiveDocument
  If .Sections.Count > 5 Then
    For i = 6 To .Sections.Count
      With .Sections(i).Range
        If .ContentControls.Count > 3 Then
          strTmp = .ContentControls(2).Range.Text
          For j = 3 To .ContentControls.Count
            strTmp = strTmp & ":" & .ContentControls(j).Range.Text
            If j > 3 Then Exit For
          Next j
          If Not .ContentControls(5).PlaceholderText = .ContentControls(5).Range.Text Then
          strTmp = strTmp & .ContentControls(5).Range.Text
          End If
          For Each oCel In .Tables(1).Range.Cells
            Set rngTmp = oCel.Range
            rngTmp.End = rngTmp.End - 1
            If rngTmp.Text = vbNullString Then
              ActiveDocument.Indexes.MarkEntry Range:=rngTmp, Entry:=strTmp & employment & """" & " \f " & """" & "TOC", _
                CrossReference:="", CrossReferenceAutoText:="", _
                BookmarkName:="", Bold:=False, Italic:=False
              Exit For
             End If
          Next oCel
        ElseIf .ContentControls.Count = 0 Then
            Selection.Find.ClearFormatting
            With Selection.Find
                .Text = "Category 1:"
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindContinue
            End With
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            strTmp = Selection.Text
            Selection.Collapse
            Selection.Find.ClearFormatting
            With Selection.Find
                .Text = "Category 2:"
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindContinue
            End With
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCell
            strTmp = strTmp & ":" & Selection.Text
            Selection.Collapse
            Selection.Find.ClearFormatting
            With Selection.Find
                .Text = "Category 3:"
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindContinue
            End With
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCell
            strTmp = strTmp & ":" & Selection.Text
            Selection.Collapse
            Selection.Find.ClearFormatting
            With Selection.Find
                .Text = "Category 4:"
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindContinue
            End With
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCell
            strTmp = strTmp & ":" & Selection.Text
            Selection.Collapse
            For Each oCel In .Tables(1).Range.Cells
            Set rngTmp = oCel.Range
            rngTmp.End = rngTmp.End - 1
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox updating from combobox selection paxile2k Word VBA 0 10-26-2010 02:30 PM
Document selection procedure kennethc Word 0 09-15-2010 02:56 PM
The modification is not allowed because selection is locked aligahk06 Word 0 09-06-2010 06:28 AM
Automatic find replace after selection in dropdown vsempoux Word 0 10-28-2009 08:45 AM
Highlighted Selection on Action Settings mos7sad PowerPoint 0 10-12-2009 07:48 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:07 AM.


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