2016-12-05 1 views
0

일반 VBA에 익숙하지 않거나 Range로 작업하고 있습니다. 텍스트 줄 뒤에 확인란을 추가하고 싶지만 다음 코드는 문서의 맨 끝에있는 모든 확인란을 출력합니다. 확인란을 설정하는 범위 매개 변수를 고정해야한다고 생각하지만이를 식별하는 방법을 모르겠습니다. 문제는 체크 박스 문서의 마지막에 첨가하는 것이 아니지만은 (문서의 단부와 동일) 현재 선택/삽입 지점 후에 추가되는 것을Word-VBA : 체크 박스 범위

'http://wordribbon.tips.net/T010727_Inserting_Multiple_Graphics_in_a_Document.html 
Sub GenerateLab() 
Dim sPic As String 
Dim sPath As String 

sPath = "C:\Users\lab\Documents\PDF Gen 12-1\TestImages\" 
sPic = Dir(sPath & "*.png") 

Do While sPic <> "" 
    Selection.TypeText ("Is this an ***?") 
    Selection.TypeParagraph 
    Selection.TypeText ("***") 
    Dim objCC As ContentControl 
    Set objCC = ActiveDocument.ContentControls _ 
     .Add(wdContentControlCheckBox) 
    Selection.TypeParagraph 
    Selection.TypeText ("Not ***") 
    Dim objCC2 As ContentControl 
    Set objCC2 = ActiveDocument.ContentControls _ 
     .Add(wdContentControlCheckBox) 
    Selection.InlineShapes.AddPicture _ 
     FileName:=sPath & sPic, _ 
     LinkToFile:=False, SaveWithDocument:=True 
    sPic = Dir 
    Selection.InsertBreak (7) 
Loop 
End Sub 

답변

0

. 그 외 모든 것은 상자 앞에 추가되고 끝까지 유지됩니다. 짧은 수정

Selection.EndKey wdLine 

또는

Selection.EndKey wdStory 

오른쪽 .Add 후 라인을 추가하여 행 (또는 문서)의 끝 부분에 커서를 이동하는 것.

또 다른 가능성은 커서를 오른쪽으로 3 개 문자를 이동하는 것입니다 : 당신이 행의 끝에서 체크 박스를 추가하지 않을 경우

Selection.Move Unit:=wdCharacter, Count:=3 

이것은 대안이 될 것입니다.