workbook set property

  • 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

    Code
        Dim objWorkbook As Workbook
        Set objWorkbook = Workbooks.Open(FPath & "\" & FName)
        
    
        iRow = 1
        iCol = 1
        
        'Get the number of rows and columns
        Set iSh = objWorkbook.Sheets(5)
  • 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


  • 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


    Code
    FName = ThisWorkbook.Name
       Dim objWorkbook As Workbook
    If Not wbOpen(FName) Then
    Set objWorkbook = Workbooks.Open(thisworkwook.path & "\" & ThisWorkbook.Name)
    Else
    Set objWorkbook = FName
    End If
    
    iRow = 1
    iCol = 1
  • 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


    Code
    Set objWorkbook = Workbooks.Open(FPath & "\" & FName)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!