VBA 打开excel

Sub openExcelFile(ByVal filePath$)
Set xls = CreateObject("Excel.Application")
Set xlbook = xls.Workbooks.Open(filePath)
'xls.Visible = True
Set xlsheet = xlbook.Worksheets(1)
Application.ScreenUpdating = False
    With xlsheet
        MsgBox .[a2]
    End With
    
 Application.ScreenUpdating = True

xlbook.Close (True)
    xls.Quit
    
    Set xlsheet = Nothing
    Set xlbook = Nothing
    Set xls = Nothing
    
End Sub

 



Sub getSheetName()

For Each sht In ThisWorkbook.Sheets
    With sht
        If .Cells(2, 1).Value <> "" Then .Cells(2, 1).Interior.ColorIndex = 45
        
    
    End With

Next
End Sub
Sub getSheetName()
Dim arr
Dim c As Range
For Each sht In ThisWorkbook.Sheets
 If sht.Name = "Sheet2" Then
    With sht
     
        Set St = Worksheets("sheet1")
           'MsgBox St.[a1].End(2).Column
        For i = 1 To St.[a1].End(2).Column 'St.[a65536].End(3).Row
           If St.Cells(1, i).Value = .Name Then
           
            
                For ii = 1 To .[a65536].End(3).Row
                    'If .Cells(ii, 1).Value Then
                    
                    Set c = St.Range(St.Cells(1, i), St.Cells(St.Cells(65536, i).End(3).Row, i)).Find(.Cells(ii, 1), , , 1)
                    If Not c Is Nothing Then
                        MsgBox "a"
                    End If
                Next
                
                Exit For
           End If
            'If .Cells(2, 1).Value <> "" Then .Cells(2, 1).Interior.ColorIndex = 45
        
        Next
    End With
 End If
Next
End Sub

posted on 2013-09-12 00:37  鱼东鱼  阅读(870)  评论(0编辑  收藏  举报

导航