Hi,
The below code, set objworkbook opens an excel file. in my case, the excel file is already open. How to replace this set line to accommodate the already opened excel file
Hi,
The below code, set objworkbook opens an excel file. in my case, the excel file is already open. How to replace this set line to accommodate the already opened excel file
Where do you get a value for Fname? It's hard to give a complete answer without seeing the full code. Maybe something like this
Function wbOpen(wbName As String) As Boolean
' returns TRUE if the workbook is open
wbOpen = False
On Error GoTo wbNotOpen
If Len(Application.Workbooks(wbName).Name) > 0 Then
wbOpen = True
Exit Function
End If
wbNotOpen:
End Function
Sub TestOpen()
Dim objWorkbook As Workbook
If Not wbOpen(fName) Then
Set objWorkbook = Workbooks.Open(FPath & "\" & fName)
Else: Set objWorkbook = fName
iRow = 1
iCol = 1
'Get the number of rows and columns
Set iSh = objWorkbook.Sheets(5)
End Sub
Display More
Hi,
Thanks for the prompt response.
Fname is the activeworkbook name.
Now getting an error on this libe : - If Not wbOpen(FName) Then
Error: Byref argument type mismatch
Thisworkbook refers to the workbook that contains the code.
Activeworkbook is the active workbook.
If fName refers to ThisWorkBook then it must be open so you don't need to check
i know that...the purpose was never to check if the file is open or not.. i know the file will be open...i just wanted to know in this case when my file will be opened how the below line should be rewritten. set objworkbook should refer to active workworkbook
Don’t have an account yet? Register yourself now and be a part of our community!