I'm trying to set a public workbook variable behind a command button on UserForm to use later in a module just to read data from it as source workbook with vlookup in VBA. I could not find a way to make this without opening the file, so I used below and then closed the file;
Set wb = Application.Workbooks.Open(filepath, UpdateLinks:=False)
wb.Close SaveChanges:=False
Also in one module I set variable as public as below;
Public wb As Workbook
But I noticed that I think because I close source workbook after setting, when VBA reaches to code line in module which is looking for already set source workbook, it gives error in vlookup function.
Actually, I never want source file to be opened. Because file is so big and open/close operations takes a lot of time. Data can be read in other file by vlookup etc. formula without opening the source but I need to do this via VBA. As result, is it possible to use a source workbook to get data from it without opening with application.vlookup?
ExcecuteExcel4Macro
– JvdV