Results 1 to 7 of 7

Modify code to work with xls and xlsx files

Threaded View

CJ-22 Modify code to work with xls... 08-30-2013, 08:17 PM
Solus Rankin Re: Modify code to work with... 08-30-2013, 10:14 PM
CJ-22 Re: Modify code to work with... 08-30-2013, 10:26 PM
CJ-22 Re: Modify code to work with... 08-30-2013, 10:33 PM
jindon Re: Modify code to work with... 08-30-2013, 10:20 PM
jindon Re: Modify code to work with... 08-30-2013, 10:37 PM
CJ-22 Re: Modify code to work with... 08-31-2013, 11:21 AM
  1. #1
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125

    Modify code to work with xls and xlsx files

    Hello,

    I have a code (probably found it on this forum) that opens up an Open Dialog Box to open another Excel Workbook. When you select the Excel Workbook you want to open, it copies data from the first workbook to the new one and saves the file. It works great except it will only open .xls files. My work is starting to use .xlsx files now and I need to update the code. Can someone help modify this code to be able to open .xls and .xlsx files? Thanks for any help and here is the code.


    Private Sub CommandButton2_Click()
    
    MsgBox "Select File to Open."
    
    Dim wb As Workbook
    
    ' speed up by turning screenupdating off
        Application.ScreenUpdating = False ' turn off the screen updating
    
    ' set workbooks
        Set MasterWB = ActiveWorkbook
    
    ' open file browser and select XLS files only, end macro if no file is selected
        newFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Select COMMENTS report for import")
        If newFN = False Then
            MsgBox "No file selected."
            Exit Sub
        End If
    
    ' open selected workbook in read only and copy all cells of worksheet 1
        Set wb = Workbooks.Open(newFN, True, False)
        
        Sheets("Setup").Select
        Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("D6").Select
        ActiveCell.FormulaR1C1 = "='Record'!R[-5]C[1]"
        Range("D6").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("E40").Select
        ActiveCell.FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
        Range("E41").Select
        Sheets("Record").Select
        Range("A1").Select
    ' close workbook without saving changes and free memory
        'wb.Close False
        'Set wb = Nothing
        
    ' turn screenupdating back on
        Application.ScreenUpdating = True ' turn on the screen updating
        
        Sheets("Setup").Select
        Range("A1:G67").Select
        Application.CutCopyMode = False
        Selection.Copy
        
        Sheets("Record").Select
        
    End Sub
    Last edited by CJ-22; 08-31-2013 at 11:23 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. modify SUMIF to work w/ closed files
    By Mathiasben in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-26-2013, 11:29 AM
  2. Merge Data from different .xlsx files & different sheet to a new .xlsx
    By QcSylvanio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2012, 01:11 PM
  3. How to add the columns data of several xlsx files of a folder in another xlsx file
    By ravikumar00008 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-25-2012, 04:29 AM
  4. VBA code to turn CSV files into XLSX
    By bryanbak3 in forum Excel General
    Replies: 1
    Last Post: 04-06-2012, 06:24 PM
  5. [SOLVED] modify xlsx files with excel 2003
    By mallorypr in forum Excel General
    Replies: 0
    Last Post: 07-10-2006, 10:19 AM

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