+ Reply to Thread
Results 1 to 5 of 5

vba: Edit very big file without uploading in excel

Hybrid View

  1. #1
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    vba: Edit very big file without uploading in excel

    My file is big with 10 million rows
    I want to accomplish Find and replace multiple sting operations
    Can this be done in vba without uploading in excel?
    Then save the edited file in asked folder name ?

  2. #2
    Registered User
    Join Date
    09-01-2011
    Location
    georgia
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: vba: Edit very big file without uploading in excel

    There isn't a whole lot of information given but this should be possible with a custom script. I've written similar scripts in C# but you can with VBA as well to access your file and adjust the data.

    Again, without knowing what type of file it is and what you want done specifically, it is a very broad question to answer.

  3. #3
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: vba: Edit very big file without uploading in excel

    Its a text file !!

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: vba: Edit very big file without uploading in excel

    Quote Originally Posted by maria.blue44 View Post
    My file is big with 10 million rows
    ...which prompts the question should it be in Excel in the first place? This implies at least 10 sheets filled to the bottom row and i can't help thinking that Access or some other database software would be more efficient.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    09-01-2011
    Location
    georgia
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: vba: Edit very big file without uploading in excel

    I am only posting this as a demonstration that this can be done. I am by no means stating that this will work for anything other than my small test I have done with the code.

    - It will ask for the source file path
    - It will ask for a full path for the output file it's going to create
    - It will ask the string you want to find. I used "test"
    - It will ask the string you want to replace it with. I used "TEST"
    - It will ask you if there's a delimiter between data in the rows
    - It will process the data until it's done. (I was too lazy to add any error checking which is the reason for the disclaimer below)

    VERY BIG DISCLAIMER: USE AT YOUR OWN RISK
    If you want to test this, I suggest copying the file and run the test on a duplicate so the original remains unaffected.

    Macro:
    Dim FilePath As String
        Dim FilePathTo As String
        
        Dim findthis As String
        Dim replwiththis As String
        
        Dim delimiter As String
        
        FilePath = InputBox("What is the full path of your .txt file?")
        If Dir(FilePath) = "" Then
            MsgBox "File does not exist, exiting"
            End
        End If
        FilePath2 = InputBox("What do you want to call the output file? (new file)")
        If Dir(FilePath2) <> "" Then
            MsgBox "File Already Exists, exiting"
            End
        End If
        
        findthis = InputBox("What value do you want to find?")
        replwiththis = InputBox("What value do you want to replace it with?")
        delimiter = InputBox("What is the delimiter? (Enter nothing if none)")
        
        Open FilePath2 For Output As #1
            Open FilePath For Input As #2
                Do Until EOF(2)
                    Line Input #2, LineFromFile
                    Dim newline As String
                    
                    LineItems = Split(LineFromFile, delimiter)
                    If UBound(LineItems) >= 0 Then
                        For i = LBound(LineItems) To UBound(LineItems)
                            If LineItems(i) = findthis Then
                                LineItems(i) = replwiththis
                            End If
                        Next i
                        
                        newline = Join(LineItems, delimiter)
                        Print #1, newline
                    
                    Else
                        If Len(LineFromFile) < 1 Then
                            Print #1, ""
                        Else
                            Print #1, LineFromFile
                        End If
                    End If
                    
                Loop
            Close #2
        Close #1
        MsgBox ("Done")
    Input File:
    test,test1,test2,test3
    test4,test5,test4,test3
    test2,test1,test,test
    Output File:
    TEST,test1,test2,test3
    test4,test5,test4,test3
    test2,test1,TEST,TEST

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 05-20-2014, 02:45 AM
  2. Uploading xml file
    By Alf in forum Suggestions for Improvement
    Replies: 3
    Last Post: 02-10-2014, 01:39 AM
  3. [SOLVED] How to allow the user to choose the file when uploading a file using a Macro
    By SarahB2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2012, 03:09 PM
  4. Uploading Excel file on-line
    By aposatsk in forum Excel General
    Replies: 1
    Last Post: 07-27-2006, 09:15 AM
  5. uploading excel floppy file onto microsoft works
    By olli owl in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-24-2006, 10:10 AM

Tags for this Thread

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