Results 1 to 2 of 2

Thread: read an excel file

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    brooklyn
    Posts
    48
    I have an excel file named "payrollfile.xls", How can I find out the name the sheets in the file?

    Thank you very, very much.

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Try This Mr.Payroll:


    ________________________________________________________
    Option Explicit

    Sub Nitro_Form_Name()
    Dim MyXL As Object
    Dim ExcelWasNotRunning As Boolean
    On Error Resume Next
    'If the application isn't running, an error occurs

    Set MyXL = GetObject(, "Excel.Application")
    If Err.Number <> 0 Then ExcelWasNotRunning = True

    Err.Clear

    ' Set the object variable to reference the file you want to see.
    Set MyXL = GetObject("c:\payrollfile.xls")
    MyXL.Application.DisplayAlerts = False

    'Show Excel
    'MyXL.Application.Visible = True
    'MyXL.Parent.Windows(1).Visible = True

    ' Do manipulations of your file here
    Dim str_Data As String
    Dim int_X As Integer
    For int_X = MyXL.Worksheets.Count To 1 Step -1
    str_Data = str_Data & MyXL.Sheets(int_X).Name & vbCrLf
    Next

    MsgBox str_Data

    If ExcelWasNotRunning = True Then MyXL.Application.Quit
    Set MyXL = Nothing
    End Sub
    Chemically Formulated As:
    Dr. Nitro

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