chetan Allipur

chetan Allipur

  • NA
  • 541
  • 169k

Please convert correct to c#. It is in VBA.

Jul 7 2017 2:13 AM
Please Convert it to c#. I tried in online convert but that is not working. 
 
 Here is the VBA Code.
 
 
Sub CleanTandFcaptionFileds(TandFoption As Integer)
Dim fld_count As Integer
Dim f As Integer
Dim Check
fld_count = 0
fld_count = ActiveDocument.Fields.Count
If fld_count <> 0 Then
'Shy - Process based on the option selected by user
' If option 1 or 2 is selected we just need to get rid of any StyleRef fileds(10) and hyphens present.
If TandFoption = 1 Or TandFoption = 2 Then
Check = True
f = 0
On Error GoTo Looperror:
Do
Do While f < fld_count
f = f + 1
If ActiveDocument.Fields.item(f).Type = 64 And _
Left(Trim(ActiveDocument.Fields.item(f).Code), 23) = "DOCVARIABLE TablePrefix" Or _
Left(Trim(ActiveDocument.Fields.item(f).Code), 23) = "DOCVARIABLE FigurePrefix" Then
ActiveDocument.Fields.item(f).Select
If ActiveDocument.Fields.item(f).Next.Type = 10 Then
ActiveDocument.Fields.item(f).Next.Delete
fld_count = fld_count - 1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
If Selection.Words.First = "-" Or Selection.Words.First = ".-" Or Selection.Words.First = ".--" Or Selection.Words.First = "--" Then
Selection.Delete Unit:=wdCharacter, Count:=1
End If
End If
If ActiveDocument.Fields.item(f).Next.Type = 12 Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
If Selection.Words.First = "-" Or Selection.Words.First = ".-" Or Selection.Words.First = ".--" Or Selection.Words.First = "--" Then
Selection.Delete Unit:=wdCharacter, Count:=1
End If
If Mid(Trim(ActiveDocument.Fields.item(f).Code), 13, 5) = "Table" Then
If Trim(ActiveDocument.Fields.item(f).Next.Code.Text) <> "SEQ Table \* MERGEFORMAT" Then
ActiveDocument.Fields.item(f).Next.Code.Text = "SEQ Table \* MERGEFORMAT"
End If
End If
If Mid(Trim(ActiveDocument.Fields.item(f).Code), 13, 6) = "Figure" Then
If Trim(ActiveDocument.Fields.item(f).Next.Code.Text) <> "SEQ Figure \* MERGEFORMAT" Then
ActiveDocument.Fields.item(f).Next.Code.Text = "SEQ Figure \* MERGEFORMAT"
End If
End If
End If
End If
fld_count = ActiveDocument.Fields.Count
If f = fld_count Then
Check = False
Exit Do
End If
Loop
Loop Until Check = False
End If
' If option 3 is selected we need to make sure StyleRef fileds(10)and hyphens present.
' And also Table Seq fileds(12)are present with restart or no restart option.
If TandFoption = 3 Then
Check = True
f = 0
On Error GoTo Looperror:
Do
Do While f < fld_count
f = f + 1
If ActiveDocument.Fields.item(f).Type = 64 And _
Left(Trim(ActiveDocument.Fields.item(f).Code), 23) = "DOCVARIABLE TablePrefix" Or _
Left(Trim(ActiveDocument.Fields.item(f).Code), 23) = "DOCVARIABLE FigurePrefi" Then
ActiveDocument.Fields.item(f).Select
Do While ActiveDocument.Fields.item(f).Next.Type = 10 Or ActiveDocument.Fields.item(f).Next.Type = 12
ActiveDocument.Fields.item(f).Select
ActiveDocument.Fields.item(f).Next.Delete
If f + 1 > ActiveDocument.Fields.Count Then
Exit Do
End If
Loop
'Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
If Selection.Words.First = "-" Or Selection.Words.First = ".-" Or Selection.Words.First = ".--" Or Selection.Words.First = "--" Then
Selection.Delete Unit:=wdCharacter, Count:=1
End If
If Mid(Trim(ActiveDocument.Fields.item(f).Code), 13, 5) = "Table" Then
UpdateTandFcaptionFields "Table", False, True, True
End If
If Mid(Trim(ActiveDocument.Fields.item(f).Code), 13, 6) = "Figure" Then
UpdateTandFcaptionFields "Figure", False, True, True
End If
End If
fld_count = ActiveDocument.Fields.Count
If f = fld_count Then
Check = False
Exit Do
End If
Loop
Looperror:
Exit Do
MsgBox "Some Table/Figure captions may not have been updated!" & vbNewLine _
& "Please make sure to verify the all Table/Figure captions." & vbNewLine _
& "(especially the last few Tables and Figures).", vbInformation, "S-Cubed Templates"
Loop Until Check = False
End If
End If
End Sub

Answers (2)