Originally Posted by
mytheresa
when I run your code, it shows error when executing macro: "Compile Error Variable not defined", I get the "Variable not defined" error on wbBk here
Set wbBk = Workbooks(sFile) , can you help me to fix it? Thank you very much!
You are using Option Explicit that is why you are getting this error. The error will go away if you comment it out
Keep option explicit as it is is
You need to modify this block [Variable dimensioning is changed]:
Sub ImportSheet()
Dim sImportFile As String, sFile As String
Dim sThisBk As Workbook
Dim vfilename As Variant
Application.ScreenUpdating = False
with:
Sub ImportSheet()
Dim sImportFile As String, sFile As String
Dim sThisBk As Workbook, wbBk As Workbook
Dim vfilename As Variant
Dim wsSht As Worksheet
Application.ScreenUpdating = False