Click here to Skip to main content
15,924,317 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have vb.net code.

I wanted to convert this code into c#.

The code is-
VB
Sub SentencesToExcel() 
    Dim appXL As Excel.Application 
    Dim wbkXLSource As Excel.Workbook 
    Dim wbkXLNew As Excel.Workbook 
     
    Dim strSearch() As String 
    Dim var 
    Dim r As Word.Range 
    Dim j As Long 
     
    Set appXL = CreateObject("Excel.Application") 
    Set wbkXLSource = appXL.Workbooks.Open(FileName:="c:\ZZZ\Test\test2\WordList.xls") 
    Set wbkXLNew = appXL.Workbooks.Add 
     
    For var = 0 To 2 
         ' build the array of search words from the source Excel file
        ReDim Preserve strSearch(var) 
        strSearch(var) = wbkXLSource.Worksheets("Sheet1").Cells(var + 1, 1).Value 
    Next 
     ' close the source Excel file as do not need it
    wbkXLSource.Close 
     ' destroy its object
    Set wbkXLSource = Nothing 
    j = 1 
     ' for each search words
    For var = 0 To UBound(strSearch()) 
         ' make a range ovbject of the whole document
        Set r = ActiveDocument.Range 
        With r.Find 
             ' with each Found
            Do While .Execute(Findtext:=strSearch(var), Forward:=True) _ 
                = True 
                 ' expand to the sentence
                r.Expand Unit:=wdSentence 
                 ' and put in the next cell in the new Excel file
                wbkXLNew.Worksheets("Sheet1").Cells(j, 1).Value = r.Text 
                j = j + 1 
                r.Collapse 0 
            Loop 
        End With 
    Next 
    appXL.Visible = True 
     
     'wbkXLNew.SaveAs FileName:="valid_path"
     'Set wbkXLNew = Nothing
     'appXL.Quit
     'Set appXL = Nothing
End Sub 
Posted
Updated 28-Dec-11 22:38pm
v3

 
Share this answer
 
Comments
mayankshrivastava 29-Dec-11 4:44am    
i tried this but it cant convert the code.
Prasad_Kulkarni 29-Dec-11 4:51am    
You have some error in your code shrivastava.mayank, that's why its not converting it..solve your error in vb itself and paste error free code in that website..
Prasad_Kulkarni 29-Dec-11 4:48am    
thank you sir,
its really useful..
mayankshrivastava 29-Dec-11 5:00am    
how to check errors ?
I don't no anything about vb.net
Uday P.Singh 29-Dec-11 5:27am    
nice link 5ed :)
Hi You can use this link

http://converter.telerik.com/[^]

Hope this will help :)

Thanks
Vinod
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900