Variable workbook: the index does not belong to the selection

Solved
Mouftie Posted messages 234 Status Member -  
 moise -
Hello,
Hello,

I would like to work on files whose names are found in a table (TbFic)

I wrote:

Sub test()
Dim Fc As String, WbFc As Workbook
Fc = Sheets("Données").Range("B4").Value
Set WbFc = Workbooks(Fc)
WbFc.Activate
End Sub


I have an error message "The index does not belong to the selection."

Note: cell B4 is in the form "NomFichier.xlsm"

Can you help me, please? Thank you

Configuration: Windows / Firefox 38.0

2 answers

  1. Patrice33740 Posted messages 8400 Registration date   Status Member Last intervention   1 784
     
    Hello,

    The error message is due to the fact that the Fc file is not part of the collection of open files!

    To open a file, you need to use:
    Set WbFc = Workbooks.Open(FullPathOfFile) 


    --
    Best regards
    Patrice
    0
    1. moise
       

      Thank you for your intervention and for creating an xlsx file.

      0