Results 1 to 7 of 7

Problems with opening a file from Excel VBA

Threaded View

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Stockholm
    MS-Off Ver
    Excel 2003
    Posts
    33

    Problems with opening a file from Excel VBA

    Hi,

    I have a problem when I try to open a new Excel workbook with a VBA macro. I have the followin gcode

    ***********************************************
    Dim fd As FileDialog 'compare check
    Dim selectedfile As Variant
    Dim this_FullName, compare_FullName As String
    Dim this_FileName, compare_FileName As String
    Dim this_Workbook, compare_Workbook As Workbook
    
    this_FullName = ThisWorkbook.FullName
    this_FileName = Dir(this_FullName)
    Set this_Workbook = Workbooks(this_FileName)
    this_Workbook.Activate
             
    ' -------------------------------------------------------
    ' select file to compare with
    
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
    With fd
    
        If .Show = -1 Then
    
            For Each selectedfile In .SelectedItems
    
                compare_FullName = selectedfile
    
            Next selectedfile
        Else
        End If
    End With
    ' ------------------------------------------------------
    
    Set fd = Nothing
    
    compare_FileName = Dir(compare_FullName)
    
    Workbooks.Open fileName:=compare_FullName
    Set compare_Workbook = Workbooks(compare_FileName)
    this_Workbook.Activate
    
    'Here I want to move data between the two workbooks
    
    End Sub
    ****************************************************

    It opens the selected file but then it starts the sub routine all over again without moving the data.

    Any ideas?

    Best Regards
    Stefan
    Last edited by arlu1201; 08-14-2012 at 04:21 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