Results 1 to 7 of 7

Thread: Excel formatting in VB

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2001
    Location
    Chicago, IL
    Posts
    49

    Excel formatting in VB

    Need some help guys, how do I programmaticly format column 2 and 4 in an excel worksheet to be a number without a decimal place?

    I am using the following objects..

    Dim xlApp As New Excel.ApplicationClass()
    Dim xlSheet As Excel.Worksheet
    Dim xlBook As Excel.Workbook


    Many thanks!

    - Darren

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    An example that might help you:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
    
        Dim xlApp As New Excel.Application()
        Dim xlWb As Excel.Workbook = xlApp.Workbooks.Add
        Dim xlSt As Excel.Worksheet = xlWb.ActiveSheet
        xlSt.Range("B:B,D:D").NumberFormat = "0"
        xlApp.Visible = True
    
    End Sub
    Couldn't help the smiley in the code there, I think you understand waht should be there instead

    /Leyan

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2001
    Location
    Chicago, IL
    Posts
    49
    Ok, I just tried that and got this error..

    Server Error in '/freight' Application.
    --------------------------------------------------------------------------------

    Exception from HRESULT: 0x800A03EC.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC.



    On this line.. xlSheet.Range("B:B,D").NumberFormat = "0"

    Any thoughts?

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2001
    Location
    Chicago, IL
    Posts
    49
    Never mind, silly smiley faces ;/

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2001
    Location
    Chicago, IL
    Posts
    49
    That didnt seem to work (

  6. #6
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Well it has to be about the smiley in the code I posted. It should be:

    ("B : B , D : D")

    without the spaces. If I remove the last space this page translates the D and the colon to a smiley.

    /Leyan

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2001
    Location
    Chicago, IL
    Posts
    49
    Ok works, thanks

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