CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    How to use Alignment (Center, etc) a cell in an Excell Sheet using VB code?

    Hiya all,

    Quick question? How to align a cell in an excell sheet using VB code? Thanx for you help!


  2. #2
    Join Date
    Mar 2001
    Location
    Australia
    Posts
    146

    Re: How to use Alignment (Center, etc) a cell in an Excell Sheet using VB code?

    The following example shows how to set Horizontal and vertical alignment



    Dim xlApp as new Excel.Application
    Dim xlWorkbook as Excel.Workbook
    Dim xlSheet as Excel.Worksheet

    xlApp.Visible = true

    set xlWorkbook = xlApp.Workbooks.Add

    set xlSheet = xlWorkbook.Sheets(1)

    With xlSheet.Cells(1, 1)
    .Value = "Hello"
    .HorizontalAlignment = xlCenter ' Center
    .HorizontalAlignment = xlRight ' Right Align
    .HorizontalAlignment = xlLeft ' Left Align

    .VerticalAlignment = xlBottom ' Bottom
    .VerticalAlignment = xlCenter ' Center
    .VerticalAlignment = xlTop ' Top

    End With

    xlWorkbook.Close false

    xlApp.Quit




    Hope this helps,

    Nathan Liebke



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

Featured