Word Macro help

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word Macro help

Post by HansV »

Change the part

Code: Select all

            With source
                ' Process the comments
                For i = 1 To .Comments.Count
                    With .Comments(i)
                        StrCmt = StrCmt & vbCr & _
                            .Reference.Information(wdActiveEndAdjustedPageNumber) & _
                            vbTab & .Author & vbTab & .Date & vbTab & _
                            Replace(Replace(.Range.Text, vbTab, "<TAB>"), vbCr, "<P>") & _
                            vbTab & source.Name
                    End With
                Next i
                .Close SaveChanges:=False
            End With
to

Code: Select all

            With source
                If .Comments.Count = 0 Then
                    StrCmt = StrCmt & vbCrLf & _
                        "No comments in this document" & vbTab & vbTab & vbTab & _
                        vbTab & source.Name
                Else
                    ' Process the comments
                    For i = 1 To .Comments.Count
                        With .Comments(i)
                            StrCmt = StrCmt & vbCr & _
                                .Reference.Information(wdActiveEndAdjustedPageNumber) & _
                                vbTab & .Author & vbTab & .Date & vbTab & _
                                Replace(Replace(.Range.Text, vbTab, "<TAB>"), vbCr, "<P>") & _
                                vbTab & source.Name
                        End With
                    Next i
                End If
                .Close SaveChanges:=False
            End With
Best wishes,
Hans

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

Re: Word Macro help

Post by Sam1085 »

Hi Hans,

Thank you for help. It's working as I expected. Also, I added the same If/Else method for Word macro (provided by you) and it also working.
Thanks again!
-Sampath-