HI Team, I have scenario where I have to copy paragraphs between two headings from word document and paste it into another word document under specific section. I have created a VBA code in word document which works in Word VBA and when i modify according to our BP code stage. I am getting various error message and difficult to complete the action. Please help me resolve the action.
Here is the code which i was using in BP Code and getting the error.
Dim oDoc As Object = GetDocument(handle,document_name)
Dim w As Object = oDoc.Application
Dim srchRng As Range = Nothing
Dim srchIntroRng As Object = Nothing
Dim oRng As Object = Nothing
Dim oRng2 As Object = Nothing
Dim oDocRng As Object = Nothing
Dim Rng As Object = Nothing
Dim styltext as string = ""
Dim styl as style = Nothing
Dim lStart,lPara as long
Dim checkout as string = ""
Dim paras As Paragraphs
Dim para As Paragraph
'Dim tempRange as Range = Nothing
lStart=0
Try
srchRng = oDoc.Content
For Each fld In oDoc.Fields
If fld.Type = 13 Then
fld.Select
w.Selection.Collapse
Rng = w.Selection.Range 'capture place to re-insert TOC later
fld.Cut
End If
Next
srchRng = oDoc.Content
For lPara = lStart To oDoc.Paragraphs.Count
Numbervalue=lPara+2
checkout="im n"
checkout = w.Paragraphs(1).Range.Text
If oRng2.FormattedText=StartHeading Then
oRng.Start = oRng2.Start - 1
'bEndFound = True
Exit For
End If
Next para
Numbervalue=oRng.Start
'Numbervalue=oDoc.Paragraphs.Count
For lPara = oRng.Start+1 To oDoc.Paragraphs.Count
'Numbervalue=lPara
styl=oRng2.Style
styltext=styl.NameLocal
If styltext = "Heading 1" and oRng2.Text="Introduction" Then
oRng.End = oRng2.Start - 1
'bEndFound = True
Exit For
End If
Next lPara
OutputData=oRng.FormattedText
lbl_Exit:
oDoc = Nothing
oRng = Nothing
oDocRng = Nothing
srchRng=Nothing
Catch ex As Exception
Dim trace = New Diagnostics.StackTrace(ex, True)
Dim line As String = Strings.Right(trace.ToString, 5)
OutputData=checkout
ErrorMessage="Error Line Number: " & line & ex.Message
'ErrorMessage=ex.Message
Finally
w = Nothing
srchRng = Nothing
Rng = Nothing
ORng = Nothing
End try