Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

WrapText in Columns in Excel sheet via .net

vb.net 2003
excel 2003

What I need:
Select Columns  G ang H
Format the Column to WrapText in the excel sheet

' current code from .net
XL.Visible = True 'open excel
        xlWB = XL.Workbooks.Open(xlPath) 'open the workbook
        xlWS = xlWB.Worksheets("GPS Worksheet") 'set the worksheet

        Dim SpecialChars As String = "!@#$%^&*()_+-={}|:<>?,[]./;"
        Dim Rng As Excel.Range
                ' delete special characters
        With xlWS
            Rng = XL.Intersect(.Range("A:A"), .UsedRange)
        End With
        For r As Integer = 1 To Rng.Rows.Count
            For c As Integer = 0 To SpecialChars.Length - 1
                Rng.Cells(r, 1).Value = Rng.Cells(r, 1).Value.ToString.Replace(SpecialChars.Chars(c), "")
            Next
        Next
        ' make the call to run
        xlWB.Application.Run(mcrName)
         '<-------------------  ' run the code to wraptext here...
Thanks
fordraiders
Avatar of Rog D
Rog D
Flag of United States of America image

On thing I have tried in the past was the following trick...

In excel record a macro.  Then record any action you want.

After you record it you can easily look at the VBA code in the macro and see how this action was done.

It will definately help you with other things in programming from VB VB.Net to Excel.

Rog
ASKER CERTIFIED SOLUTION
Avatar of Rog D
Rog D
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial