Results 1 to 4 of 4

Switching between workbooks

Threaded View

  1. #1
    Registered User
    Join Date
    02-15-2006
    Posts
    93

    Switching between workbooks

    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
    Last edited by mudraker; 09-23-2007 at 02:15 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1