Excel VBA Course

(35% Sale Ends Jan. 26)

Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course (35% Discount)

add procedure to open file and close based on userform



may  be  my  question is  weird . I  hope is  logical. I  have  the  userform  in file  DESTENATION .it  designed  based on file  SOURCE . so  what  I want  when  I try  running the  userform  from  file  DESTENATION should   open  the  file  SOURCE  to  populate  data in listbox  and  search  based on textbox 1 with  column 4 in listbox   into file DESTENATION and  when  close  the  userform should  close  the  file SOURCE . 

note: if  you  try  running   the  userform   for file  DESTENATION it  will show  error  becuase   there is  no  data link  with  it   yet.

any  idea  to  achieve  this  experts ,please?



Selected Answer


Please see Don's tutorial Macro to get Data from Another Workbook in Excel to see how to extract data from another workbook (set as wb say). You may need to change portions of your code to identify the workbook e.g. in your UserForm_Initialze macro, open, define data and close like this:

Dim Wb As Workbook   
Set Wb = Workbooks.Open("full path to SOURCE.xlsm")
Set rngDB = Wb.Sheets(1).Range("A2:J20")
. ' your code to populate controls
Wb.Close SaveChanges:=False
Hope this helps.


brilliant !  I  was  needing  for  this  solution . truly  I  don't  expect theses simple  lines  do  that. I excpected to  need  more  complicated as writing   many  lines into  the code. great assistance !  many  thanks John .
Mussa (rep: 22) Dec 2, '21 at 3:39 pm
Glad it helped, Mussa. Thanks for selecting my Answer but credit goes to Don too  (for this site and his tutorials)
John_Ru (rep: 2857) Dec 2, '21 at 3:43 pm
Add to Discussion

Answer the Question

You must create an account to use the forum. Create an Account or Login