Good evening,
I am trying to import data from one workbook into another but it is not working. Any ideas on what is happening? This is something I am piecing together from other posts but I have hit a snag.
Sub Updating()
Dim ImportFileName as Variant
Dim CFileNeams as Variant
CFileName = ActiveWorkbook.Name
MainMenu.Hide
spath = CurDir
ChDrive ThisWorkbook.Path
ChDir ThisWorkbook.Path & "\Import File"
ImportFileName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=False)
If ImportFileName = False Then
MsgBox "Error"
MainMenu.Show
Else
Workbooks.Open Filename:=ImportFileName
End If
ImportFileName = ActiveWorkbook.Name
Application.WindowState = xlMinimized
Windows(ImportFileName).Activate
Sheets("Setup1").Select
Cells.Copy
Windows(CFileName).Activate
Sheets("Setup").Select
Range("A1").PasteSpecial Paste:=xlPasteValues
Application.WindowState = xlMaximized
End Sub
It works up until Windows(CFileName).activate
I am not sure what is happening here as I have checked, using a message box, and CFileName still has the correct file name. For some reason excel will not switch to the other file. If I switch this to Windows("Workbooks name.xls").activate the code works.
Any ideas? As always, thank you in advance for your help!
tc
Bookmarks