none
System.MissingMemberException: 'Public member 'Selection' on type 'Worksheet' not found.' RRS feed

  • Question

  • hi all

    i want to send record to excel using vb.net

    when i want to select two cells i see this error:

    System.MissingMemberException: 'Public member 'Selection' on type 'Worksheet' not found.'
    

    my code is :

       Dim xlApp As Excel.Application
            Dim xlWorkBook As Excel.Workbook
            Dim xlWorkSheet As Excel.Worksheet
    
    
            ' THE EXCEL NAMESPACE ALLOWS US TO USE THE EXCEL APPLICATION CLASS
    
            xlApp = New Excel.Application
            xlWorkBook = xlApp.Workbooks.Open(appPath & "\Shop.xlsx", CorruptLoad:=True)           ' WORKBOOK TO OPEN THE EXCEL FILE.
            xlWorkSheet = xlWorkBook.Worksheets("Shop")    ' THE NAME OF THE WORK SHEET. 
    
            xlApp.Visible = True
    
            xlWorkSheet.Activate()
    
            Dim iRow As Integer = 1
    
    
       Dim DataRow As Byte = 0
    
    
            For Counter = 1 To DsReports.QPaiShop.Count
    
    
    
                xlWorkSheet.Cells(iRow, 1) = DsReports.QPaiShop.Rows(DataRow)("Description").ToString
                xlWorkSheet.Cells(iRow, 2) = DsReports.QPaiShop.Rows(DataRow)("Quanty").ToString
                xlWorkSheet.Cells(iRow, 3) = DsReports.QPaiShop.Rows(DataRow)("OrderPrice").ToString
                xlWorkSheet.Cells(iRow, 4) = DsReports.QPaiShop.Rows(DataRow)("TotalPrice").ToString
                xlWorkSheet.Cells(iRow, 5) = DsReports.QPaiShop.Rows(DataRow)("OrderDiscountPrecent").ToString
                iRow = iRow + 1
                DataRow = DataRow + 1
            Next Counter
    
    
            iRow = iRow + 1
    
    
     xlWorkSheet.Range("B" & iRow & ":D" & iRow).Select()
    
            'With xlWorkSheet.Selection
            '    '.HorizontalAlignment = xlCenter
            '    '.VerticalAlignment = xlCenter
            '    .WrapText = False
            '    .Orientation = 0
            '    .AddIndent = False
            '    .IndentLevel = 0
            '    .ShrinkToFit = True
            '    '.ReadingOrder = xlRTL
            '    .MergeCells = False
            'End With
            'xlWorkSheet.Selection.Merge
    
            xlWorkSheet.Cells(iRow, 2).Merge
    
    

    how to solve it?


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Friday, November 23, 2018 7:10 AM

Answers

  • Hi,

    You can use this method,merge B1:D3

    xlWorkSheet.Range("B1:D3").Select()

    xlWorkSheet.Range("B1:D3").MergeCells = True

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sh 2020 Friday, November 23, 2018 8:57 AM
    Friday, November 23, 2018 8:17 AM
  • Hi,

    select B1:D3

    xlWorkSheet.Range("B1:D3").Select()
    merge B1:d3
     xlWorkSheet.Range("B1:D3").MergeCells = True

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sh 2020 Friday, November 23, 2018 8:56 AM
    Friday, November 23, 2018 8:40 AM

All replies

  • Hi,

    You can use this method,merge B1:D3

    xlWorkSheet.Range("B1:D3").Select()

    xlWorkSheet.Range("B1:D3").MergeCells = True

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sh 2020 Friday, November 23, 2018 8:57 AM
    Friday, November 23, 2018 8:17 AM
  • thanks dear 

    i used this code ..

            xlWorkSheet.Range("B1:D3").Select()
            xlWorkSheet.Range(iRow, 2).MergeCells = True

    and see this error

    how to solve it?


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Friday, November 23, 2018 8:25 AM
  • Hi,

    select B1:D3

    xlWorkSheet.Range("B1:D3").Select()
    merge B1:d3
     xlWorkSheet.Range("B1:D3").MergeCells = True

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sh 2020 Friday, November 23, 2018 8:56 AM
    Friday, November 23, 2018 8:40 AM