Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > paste special function in vb.net convert VBA to vb.net


Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2012, 05:35 AM
arun_ajay2000 arun_ajay2000 is offline
Newcomer
 
Join Date: Apr 2012
Posts: 1
Default paste special function in vb.net convert VBA to vb.net


Hi,
Hi, Im new to VB programming. can anyone help me out to convert given VBA code to vb.net. this function is designed to convert all excel workbook data to value using pastespecial function.
Thank you in advance.
Code:
Sub ConvertAllToValues()
     '
     'Originally Adapted from OZgrid.com
     '
    Dim OldSelection As Range
    Dim HiddenSheets() As Boolean
    Dim Goahead As Integer, n As Integer, i As Integer
    Goahead = MsgBox("This will irreversibly convert all formulas in the workbook to values. Continue?", vbOKCancel, "Confirm conversion to values only")
    If Goahead = vbOK Then
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
         
        n = Sheets.Count
        ReDim HiddenSheets(1 To n) As Boolean
         
        For i = 1 To n
            If Sheets(i).Visible = False Then HiddenSheets(i) = True
            Sheets(i).Visible = True
        Next
         
        Set OldSelection = Selection.Cells
        Worksheets.Select
        Cells.Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues
         
        Cells(OldSelection.Row, OldSelection.Column).Select
        Sheets(OldSelection.Worksheet.Name).Select
         
        Application.CutCopyMode = False
         
        For i = 1 To n
            Sheets(i).Visible = Not HiddenSheets(i)
        Next
         
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
    End If
End Sub

Last edited by Cerian Knight; 04-09-2012 at 09:58 AM. Reason: Added [code]...[/code] tags
Reply With Quote
  #2  
Old 04-09-2012, 09:52 AM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,740
Default

This code is native VBA, which Excel uses directly. Therefore, confirm that you are trying to automate Excel using VB.NET? Also, show us what you have tried, since it is not the intent of this forum to do complete code-conversions for you.

BTW: I split this out to its own thread (and removed a duplicate post in another thread), since it did not see any relevance to the thread topic you had posted in. Please have a look at our Posting Guidelines when you have a chance. Thanks and welcome to the forum.
__________________
"May the code that you write never work in ways that you didn't expect; and may the code that you didn't write never require you to maintain it". - Ancient Chinese Proverb

Last edited by Cerian Knight; 04-09-2012 at 09:57 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->