Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Excel Application by VBA

Status
Not open for further replies.

tamkas

Programmer
May 18, 2007
5
CA
Hey guys,

I am very new to VBA. I am just trying to create excel application by VBA. It gives me an error: 0

Code:
Private Sub Command27_Click()
   On Error GoTo ErrorHandler
   
   Dim xlApp As Excel.Application
   Dim myFile As Excel.Workbook
   Dim mySheet As Excel.Worksheet
   
   Dim strprocessingLevel As String
   
   If MsgBox("Confirm exporting to Excel?", vbYesNo + vbQuestion) = vbNo Then
   Exit Sub
   End If
   
   SysCmd acSysCmdSetStatus, "Processing Data to Export...."
   
   '----------------------------------------------- Open Excel application and create new file
    
   strprocessingLevel = "Creating objects"
   
   Set xlApp = CreateObject("Excel.Application")
   Set myFile = xlApp.Workbooks.Add
   Set mySheet = myFile.Worksheets(1)
   
   With mySheet
        strprocessingLevel = "Inserting Header Information"
        
        'Report Header Setup
        .Cells(1, 1) = "LeoTV Live - Non Learning Revoceries"
        .Cells(2, 1) = "Statement of Charges: Fiscal "
        
   End With
   
ErrorHandler:
   MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, vbExclamation
End Sub

Thanks
 
You need to put:

Code:
    ...
    End With
[blue][b]Exit Sub[/b][/blue]
Error Handler:
...



-V
 
Explanation: you don't actually have an error (0 means no error). Your code is just "falling through" to the error handler because you didn't have the Exit Sub between the main code and the error handler.

If this were a function you would need Exit Function.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top