+ Reply to Thread
Results 1 to 11 of 11

Help to Search for and in a Text file for a desired string

  1. #1
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Help to Search for and in a Text file for a desired string

    Hello,

    I am brand new to excel VBA, and have been doing some work for a company that i am an intern for with it, but i am having difficulties with figuring out how to write the second part of code for a program i am trying to write. Initially the program takes in 4 inputs from the User, puts them into empty cells 1-4 and in the 5th cell is a password that must be copied as an output and placed into a text (.h) file after a specific position in place of the old password. Oh but it also has to copy the old file and save it as old.h incase there is a problem. What i am having the most difficulty with is trying to make a program that will search for specific line and input the 4 digit string in place of the old string. Also i have no cluse how to copy a file into a new text file with a new name besides reading the old file and writing the new one, but then it runs in one consecutive line. I dont know if this makes sense so basically what i am trying to do is:

    Make a program that:

    1. Searches for A .h (text) file
    2. Copies the .h file into another file to save a copy of the old file.
    3. Reads through the text file until it finds a specific line.
    4. After the line is read a 4 digit string from a predefined value replaces the one in the initial program.
    5. Saves the new file.

    I can give more information if needed, i am not someone that uses forums, so i dont know the best way to write my problem.
    Last edited by Taylorez; 10-14-2010 at 06:54 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Help to Search for and in a Text file for a desired string

    Hello Taylorez,

    This macro will change the password in the file. There are two important pieces of information that needed for this to work. The location of the new and old passwords.

    This macro will display the Open File dialog. You can then select the folder and file you want to open. The default files shown are *.h, *.txt, and *.csv. You also can choose "All Files".
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help to Search for and in a Text file for a desired string

    Thanks! Checking the code now, looks great thx a lot!

  4. #4
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help to Search for and in a Text file for a desired string

    Just one question, my old password is in the .h file so i have no idea what it is.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Help to Search for and in a Text file for a desired string

    Hello Taylorez,

    Is the old password always located in the same place?

  6. #6
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help to Search for and in a Text file for a desired string

    It should be, the only problem being if the .h file changes and the password moves. Any ideas?

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Help to Search for and in a Text file for a desired string

    Hello taylorez,

    Can you post a couple of these old files? It will help me establish a pattern (if there is one).

  8. #8
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help to Search for and in a Text file for a desired string

    Here is a chunk of the .h file... Then one that i am searching in. I Have put "This is the line taht i am searching for" above it:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help to Search for and in a Text file for a desired string

    Alright, so i have managed to make it find the desired portion of the string, only problem is that now it is pasting more than just the code to the right of the password after the password. So it is duplictaing some of my code. I am playing around with the right side operator, but i am having a heck of a time. Any suggestions?

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Help to Search for and in a Text file for a desired string

    Hello Taylorez,

    Will this string be the only one in the file ending with _PASSWORT?

  11. #11
    Registered User
    Join Date
    10-12-2010
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help to Search for and in a Text file for a desired string

    Yeah, it is but i managed to fix it this morning... i think thanks for the help it was awesome!

+ Reply to Thread

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