Hello,
I am having trouble with this code, which was working perfectly until it stopped printing all of a sudden or only prints the very last page. After testing it a little I figured it was still identifying the right pages but not giving the command to print. I bolded and highlighted below the part I think is causing the issue. When I deleted the "Range" part it printed out the whole document normally.
I am not sure how to solve this issue so any help is appreciated.
Sub printDCSum() Dim endCount As Integer Dim pag1 As String Dim blnFound As Boolean Dim diTag As Boolean Dim inaccurateString As String Dim cc As ContentControl Dim answer As Boolean ActiveDocument.Range.Select Selection.Find.Text = "Discharge Instructions" blnFound = Selection.Find.Execute endCount = ActiveDocument.ComputeStatistics(wdStatisticPages) startCount = Selection.Information(wdActiveEndAdjustedPageNumber) pag1 = startCount & "-" & endCount - 1 pag2 = endCount & "-" & endCount 'MsgBox (pag1) test message box '''first make sure that every content control in the discharge summary is autofilled. If a content control cannot be found then set boolean to notify user to check D/C summary manually. ''unlock all content controls For Each cc In ActiveDocument.ContentControls cc.LockContentControl = False Next 'check the following variables and replace if inaccurate Call setDCVal("Rec Diet", "Rec Diet", inaccurateString) ''re-lock controls For Each cc In ActiveDocument.ContentControls cc.LockContentControl = True Next ''if there are inaccurate variables, ask the user if they would like to print anyway answer = True ''defaul answer as true If inaccurateString <> "" Then answer = MsgBox(inaccurateString & " could not be verified by the code. Would you still like to print?", vbYesNo) End If If answer = True Then Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Copies:=2, Pages:=pag1 Set ccGroup = ActiveDocument.SelectContentControlsByTitle("Data Entry Value") For Each cc In ccGroup If cc.Range.Text <> "None" Then diTag = True Next cc Set ccGroup = ActiveDocument.SelectContentControlsByTitle("Record Retrieval Value") For Each cc In ccGroup If cc.Range.Text <> "None" Then diTag = True Next cc Set ccGroup = ActiveDocument.SelectContentControlsByTitle("Special Instructions Value") For Each cc In ccGroup If cc.Range.Text <> "None" Then diTag = True Next cc If diTag Then Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Copies:=1, Pages:=pag2 'MsgBox ("Data If Activated") End If MsgBox ("Discharge Summary Printed") Else MsgBox ("Discharge Summary was not printed") '04.06.18 ls End If End Sub