CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Excel and VB

  1. #1
    Join Date
    Aug 2001
    Posts
    14

    Excel and VB

    Dear Gurus,
    I am using Excel2000 for printing reports of an Visualbasic application. I have included the references (excel5.0 reference)in my project. I am not able to get the properties like
    .cells(1,1).width and so on. I am able to access the cell and enter data into it. But not the width property or the font property of the cell and so on. What else should i include.

    The other problem is :
    I am showingthe excel worksheet when a button is clicked. by using xlsheet.application.visible=true . after the application is closed and i click the button again excel is unable to show the sheet.
    in the click event i have added the code like
    set xlsheet = xlbook.worksheets.add
    Please clarify urgently.

    Thank you.


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

    Re: Excel and VB

    You should add a reference to
    microsoft excel 9.0 object library

    About the sheet matter, this may help:

    private Sub Command2_Click()
    'xlapp and xlSheet are declared in general section of form as
    'private withevents xlApp as Excel.Application
    'private withevents xlSheet as Excel.Worksheet

    If Not xlApp.ActiveWorkbook is nothing then
    If xlApp.Worksheets.Count = 0 then
    'it should never happens. It is here only
    'to handle error situations
    set xlSheet = xlApp.Worksheets.Add
    else
    set xlSheet = xlApp.Worksheets(1)
    End If
    else
    'this should be your case:
    xlApp.Workbooks.Add
    set xlSheet = xlApp.Worksheets.Add
    End If
    End Sub




    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