Results 1 to 3 of 3

File name without file path (data import) - Excel crash

Threaded View

  1. #1
    Registered User
    Join Date
    11-13-2012
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    6

    File name without file path (data import) - Excel crash

    Hi, I've got the following Import macro, that imports data from another Excel file:

    Sub Import()
    
    Dim File As Variant
    Dim Filename As Variant
    Dim Master As Variant
    
    MsgBox "Choose file", vbOKOnly
    File = Application.GetOpenFilename("Excel files (*.xls),*.xls", , "Open an Excel file...")
    
    If Not File = False Then Workbooks.Open (File)
    
    Master = ThisWorkbook.Name
    
        Filename = Right(File, 20)
      
        Sheets(1).Activate
        Range("G11").Select
        Selection.Copy
        Windows(Master).Activate
        Range("G11").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows(Filename).Activate
    
        Range("G19").Select
        Selection.Copy
        Windows(Master).Activate
        Range("G19").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows(Filename).Activate
    
        ActiveWorkbook.Close False
       
        MsgBox "Import completed"
        
    End Sub
    Everything works fine as long as the file name consists of 20 (or whatever number we will put there) signs (including .xls) due to this line Filename = Right(File, 20).

    Is there a way to change the code in a way that it will just get the file name without specifying its exact number of signs?

    Thanks in advance!
    Last edited by exinx; 11-19-2012 at 02:04 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