none
Helps me to convert VBA Code into C# Code RRS feed

  • Question

  • Below is the VBA code to select entire row start from row 5 to row 1048576 (the Excel last row) and hide it.

    Rows("5:5").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.EntireRow.Hidden = True

    But I'm currently working with VSTO, and I'm using C#, I would like to know how to convert the VBA code above into C# code.

    Thanks......!

    Tuesday, October 27, 2015 12:02 AM

Answers

  • >>>But I'm currently working with VSTO, and I'm using C#, I would like to know how to convert the VBA code above into C# code.

    According to your description, I have created document-level Excel project base on Excel 2013 Workbook project template and changed VBA code into C# code, you could refer to below code:

    Excel.Worksheet wSheet = ((Excel.Worksheet)ActiveSheet);
    
    Excel.Range range= wSheet.get_Range("5:5",Type.Missing);
    
    range.Select();
    
    wSheet.get_Range(range, range.get_End(Excel.XlDirection.xlDown)).Select();
    
    Excel.Range selectedRange = Application.Selection as Excel.Range;
    
    selectedRange.EntireRow.Hidden = true;
    

    For more information, click here to refer about Excel Object Model Overview

    • Marked as answer by nomen86 Friday, October 30, 2015 1:51 AM
    Tuesday, October 27, 2015 9:06 AM