Results 1 to 7 of 7

Thread: (RESOLVED)accessing excel 2003 from visual studio 2005 express

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Resolved (RESOLVED)accessing excel 2003 from visual studio 2005 express

    can someone assist i am trying to access excel 2003 from Visual Studio Express 2005 express i am using the code below which opens excel but then gives me an error of com exception was unhandled and highlights the code line " owb= oxl.workbooks.add", any ideas.
    VB Code:
    1. Public Class Form1
    2.  
    3.     Public Sub New()
    4.  
    5.         ' This call is required by the Windows Form Designer.
    6.         InitializeComponent()
    7.  
    8.         ' Add any initialization after the InitializeComponent() call.
    9.  
    10.     End Sub
    11.  
    12.     Private Sub Button1_Click(ByVal sender As System.Object, _
    13. ByVal e As System.EventArgs) Handles Button1.Click
    14.         Dim oXL As Excel.Application
    15.         Dim oWB As Excel.Workbook
    16.         Dim oSheet As Excel.Worksheet
    17.         Dim oRng As Excel.Range
    18.  
    19.         ' Start Excel and get Application object.
    20.         oXL = CreateObject("Excel.Application")
    21.         oXL.Visible = True
    22.  
    23.         ' Get a new workbook.
    24.         oWB = oXL.Workbooks.Add
    25.         oSheet = oWB.ActiveSheet
    26.  
    27.         ' Make sure Excel is visible and give the user control
    28.         ' of Excel's lifetime.
    29.         oXL.Visible = True
    30.         oXL.UserControl = True
    31.  
    32.         ' Make sure that you release object references.
    33.         oRng = Nothing
    34.         oSheet = Nothing
    35.         oWB = Nothing
    36.         oXL.Quit()
    37.         oXL = Nothing
    38.  
    39.         Exit Sub
    40. Err_Handler:
    41.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
    42.     End Sub
    43.  
    44. End Class







    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by cassie1; Nov 4th, 2005 at 06:00 AM. Reason: Resolved

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