Activate excel workbook

Johny

Registered User.
Local time
Today, 20:15
Joined
Jun 1, 2004
Messages
80
Hello,

I just have a simple question:
I want to open a excel file, select a sheet and activate it (give focus).
The code beneath works but my excapp is hidden, can someone help me to show the app?

Code:
Public Function p_OpenExcelFile(ByVal file As String, ByVal sheet As String) As Byte
'---------------------------------------------------------------------------------------------
' Auteur:
'           xxx.xxx@xxxxxx.com
' Parameters:
'           file   -> location of excel file to be opened
'           sheet   -> sheet of file 'file' to be selected
' Function:
'           opens excel file 'file' and selects sheet 'sheet'
' Return:
'            0   -> Error: Other error
'            1   -> Function succeeded
'---------------------------------------------------------------------------------------------
    Dim excapp As Excel.Application
    Dim wb As Workbook
    
    Set excapp = New Excel.Application
    
    Set wb = excapp.Workbooks.Open(file)
   
    wb.Sheets(sheet).Select
    wb.Activate

    p_OpenExcelFile = 1
ExitFunction:
    Set excapp = Nothing
    Set wb = Nothing
    Exit Function

AfterError:
    MsgBox "There was an error while opening file '" & file & "':" & vbCr & vbCr & Err.Description, vbCritical, "Oops"
    Resume ExitFunction
End Function
 
omg i feel so ingnorant... thanx a million. I overlooked this property somehow
 

Users who are viewing this thread

Back
Top Bottom