Results 1 to 2 of 2

Find Active worksheet after Workbooks.Opentext???

Threaded View

  1. #1
    Registered User
    Join Date
    09-21-2007
    Posts
    3

    Find Active worksheet after Workbooks.Opentext???

    Excel 2002 SP3

    I'm trying to write a set of macros to read ; text files and do some charting.

    So I have Workbooks.OpenText working to open the data properly, but then I need to get a reference to the current sheet of which there is only one. But no reference that I try will work. They all toss an error '91 Object or With block not set.

    After I do the OpenText and make the new workbook, then I need to call a series of subs to do format the data and do some charting. The formatting - recorded from a macro, works just fine, so I know the OpenText call leaves the new data as the active sheet, but I need an object reference to the active sheet to continue with the processing, and I can't get that reference.

    The code for the first failing routine looks like this:
    Function GetDataRange()
    ' GetDataRange
    ' Return the number of rows in the data by looking for the first zero value of the time series
    
        Dim idx As Integer
        Dim jdx As Integer
        Dim interp As Double
        Dim cc As String
        Dim Wks As Worksheet ' holds the current worksheet incase we go away from it.
        Dim Win As Window ' Holds the currently active window
    
        ' Wks = Win.ActiveSheet ' Application.ActiveSheet
        Wks = Worksheets(1) ' Application.ActiveSheet
    
        For idx = 10 To 1000
            cc = Wks.Cells(idx, 1).Value
            If cc = "" Then
                Exit For
            End If
        Next idx
    GetDataRange = idx - 1 ' return the row of the last data
    End Function
    I figure I'm doing something simple and stupid, but in spite of 5 inches of books to look through I can't find a working example of what I need.

    Thanks much,
    ww
    Last edited by VBA Noob; 09-26-2007 at 06:43 PM.

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