+ Reply to Thread
Results 1 to 2 of 2

Run-Time error '91'

Hybrid View

jovir Run-Time error '91' 02-14-2013, 08:42 AM
romperstomper Re: Run-Time error '91' 02-14-2013, 09:23 AM
  1. #1
    Registered User
    Join Date
    02-08-2013
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question Run-Time error '91'

    Hello
    I'm working on an app developed in VB6 with interaction with Excel VBA
    There are two functions that Utilization properties Excel.Application
    How to use Excel.Application object in both functions?

    ***********************************
    Public Function OpenExcel()
    Dim xl As Object
    
    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open ("C:\\excelformat.xls")
    xl.Visible = True
    Set xl = Nothing
    
    End Function
    ***********************************
    ***********************************
    Public Function NewPag()
    Dim xl As Object
    
    Set xl = CreateObject("Excel.Application")
    Line = ActiveCell.Row
    Column = ActiveCell.Column
    Sheets("Plan3").Select
    Range("A1:I48").Select
    xl.Selection.Copy
    Sheets("Plan2").Select
    Range("A" & Line + 3).Select
    ActiveSheet.Paste
    Range(Column & ":" & Line + 5).Select
    Set xl = Nothing
    
    End Function
    ***********************************
    _________________________________________________________
    |Run-time error 91 (Object variable or with block variable not set).|
    _________________________________________________________
    Last edited by arlu1201; 02-14-2013 at 08:48 AM. Reason: Use code tags.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Run-Time error '91'

    Store the variable at module level, not procedure level
    Dim xl As Object
    Public Function OpenExcel()
    
    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open ("C:\\excelformat.xls")
    xl.Visible = True
    
    End Function
    
    Public Function NewPag()
    Line = xl.ActiveCell.Row
    Column = xl.ActiveCell.Column
    with xl.ActiveWorkbook
    .Sheets("Plan3").Range("A1:I48").Copy .Sheets("Plan2").Range("A" & Line + 3)
    .Sheets("Plan2").select
    .Sheets("Plan2").Cells(Line + 5, Column ).Select
    End With
    
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1