View Single Post
 
Old 02-07-2022, 05:40 AM
Puneet Singh Puneet Singh is offline Windows XP Office 2010
Novice
 
Join Date: Feb 2022
Posts: 13
Puneet Singh is on a distinguished road
Default

Thanks sir and where we keep our word document in below code. I mean where we open the word doc and paste the paragraph in below code.

Private Sub AddPara(oDoc As Document, sText As String)
Dim oRng As Range
Dim oShape As Range
Dim bProtected As Boolean
'Unprotect the file
If oDoc.Tables.Count < 3 Then
MsgBox "Incompatible document", vbCritical
GoTo lbl_Exit
End If
If Not oDoc.ProtectionType = wdNoProtection Then
bProtected = True
oDoc.Unprotect Password:=""
End If
Set oRng = oDoc.Tables(3).Range.Cells(2).Range
oRng.End = oRng.End - 1

'If you want to keep the content of the text box.....
If oRng.ShapeRange.Count > 0 Then
oRng.ShapeRange(1).Select
Set oShape = oDoc.Tables(3).Range.Cells(4).Range
oShape.Collapse 1
oShape.Text = vbCr
oShape.Collapse 0
oShape.FormattedText = Selection.FormattedText
End If
'..... end of text box code

oRng.Text = sText
'Reprotect the document.
If bProtected = True Then
oDoc.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=""
End If
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
Reply With Quote