Prev: Word 2007: ContentControl's method ToggleEditPlaceholderText i
Next: Custom Properties (Word 2007)
From: LordHog on 28 Apr 2010 13:23 Hello, I am trying create a macro that auto increments the first column (e.g., step numbers) and maintain any comments within that cell. I have a macro that will auto increment and copy the cell's comment, but once I insert the comment I can't move to the next well properly as it cursor is not within that cell where the comment was inserted. I have tried various methods, but can't get anything to work well. Below is the VBA macro that performs this task. It is not pretty, but sort of works: Sub InsertStepNumbersEx() Dim stepCount As Integer Dim startStep As String Dim aCom As Comment Dim comStr As String Dim oRng As Range Dim aSel As Selection startStep = InputBox(Prompt:="Enter the starting step number", _ Title:="Starting Step Number", Default:="0") stepCount = CInt(startStep) While Selection.Information(wdWithInTable) = True ' Select the current cell comment Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend Set aCom = Selection.Comments(1) aStr = aCom.Range.Text ' Insert the Step Numner Set aSel = Selection Selection.TypeText Text:=stepCount & "." ' Select the current cell and add the comment If Not IsEmpty(aStr) Then Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend Set oRng = Selection.Range Selection.Comments.Add Range:=oRng Selection.TypeText aStr End If Selection = aSel Selection.MoveDown Unit:=wdLine, Count:=1 stepCount = stepCount + 1 Wend End Sub Any help on getting the cursor to move back to the cell's original position is greatly appreciated. Mark
|
Pages: 1 Prev: Word 2007: ContentControl's method ToggleEditPlaceholderText i Next: Custom Properties (Word 2007) |