CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Location
    Belgium, Bruges
    Posts
    146

    Changing cell attributes in excel

    Hi,

    i am making an excel file from visual basic With the following code:

    Dim newbook as Variant
    set newbook = X.Workbooks.Add
    newbook.worksheets(1).range("A1").Value = "bla"
    newbook.worksheets(1).range("A1").Font.Bold = true



    This works fine, but there are a few things that i don't know how to do:

    Changing column width and row height
    changing the cell backcolor

    Could anybody help me please?


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Changing cell attributes in excel


    'xlsheet here is newbook.worksheets(1) in your code
    'xlapp is the variable that istantiate excel.application
    'ie:
    'private withevents xlApp as Excel.Application

    xlSheet.Range("A1").Value = "bla"
    xlSheet.Range("A1").Font.Bold = true

    xlSheet.Columns("A:A").ColumnWidth = 17.43
    xlSheet.Rows("1:1").RowHeight = 15
    xlSheet.Range("A3").Select
    With xlApp.Selection.Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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