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.
Printable View
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.
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