Results 1 to 3 of 3

Thread: [RESOLVED] Set excel range in vb.net

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2015
    Location
    Earth
    Posts
    175

    Resolved [RESOLVED] Set excel range in vb.net

    Hi experts,
    I got following VBA code from this link;
    http://www.ozgrid.com/forum/showthread.php?t=50354
    Code:
    Sub delHiddenRows() 
        Dim r As Range, k As Range 
        With ActiveSheet 
            Set r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Row) 
            Set k = r.SpecialCells(xlCellTypeVisible) 
            r.EntireRow.Hidden = False 
            k.EntireRow.Hidden = True 
            r.SpecialCells(xlCellTypeVisible).EntireRow.Delete 
            r.EntireRow.Hidden = False 
        End With 
    End Sub
    I am trying to change above VBA code to vb.net code.
    When I copy following line to vb.net,
    Code:
    Set r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Row)
    that line automatically change as following line by Visual Studio.
    Code:
    r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Row)
    In other words the Set statement disappear in Visual Studio.

    That line doesnt work in vb.net because Set statement disappear...

    Any support will be appreciated...

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: Set excel range in vb.net

    Haven't done excel with .net (MS excel API's) in loooong time.
    So you either do soemthing like
    Code:
    Dim r As new Range ' or ' Dim r As Range
    r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Row)
    There is not set in .net, or at least it's pleonasm, if is still used.
    Or, if you have issues then the best bet would be to import the excel interop object in .net and use that to program.
    Be aware that this will give tons of issues if you plan to use ASP.NET as reported by Microsoft itself, DO NOT use it in ASP.NET .
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    Banned
    Join Date
    Oct 2015
    Location
    Earth
    Posts
    175

    Re: Set excel range in vb.net

    Thanks sapator. Solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width