+ Reply to Thread
Results 1 to 4 of 4

VBA Replace Function Not Working

  1. #1
    Forum Contributor
    Join Date
    04-06-2006
    Posts
    131

    Question VBA Replace Function Not Working

    Hey Everyone,

    I am at an absolute loss as to why my Replace function is not working... I was expecting this part of my project to be easy, and the function does not give an error message or anything like that - it simply just isn't doing what it is supposed to be doing...

    I have attached 2 sample files - my Excel sheet and a Text file. Now, the Excel sheet has a lot more in it that just the problem area. I gave you everything that comes before that point as well so you could see it in context, and see what is happening leading up to it.

    To get to the problem area, do the following:
    1. Run the User Form
    2. Select Template One (or, really, any of the Templates)
    3. Fill in any random value for the ID, name, and Variable feilds (I left the sample very generic)
    4. Click the Command button to edit the Template
    5. use the Text Box on the top left to make some kind of modification - any change at all is fine
    6. Click the "Make Your Changes Permanent" button

    Now, going back a step. When you opened the Template originally (in step 2), VBA pulled that template from the .txt file. When you edit the template then click the button to make the change permanent (Steps 5 and 6), VBA is supposed to overwrite that part of the text file with the changes you made in the Text Box. I was accomplishing this by storing the original value of the template in its own Variable, then using that in a Replace function to find the original text and replace it with the new text. This is all happening, for the most part, in the Private Sub cmd_Perm_Click() section.

    Please Login or Register  to view this content.
    Now, the issue is - all of this works without giving any kind of error, but it does not actually update the .txt file with the new text from txt_Preview.Value. I am at an absolute loss as to why it is not working... Any help would be greatly appreciated!!!

    Thanx everyone!!!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA Replace Function Not Working

    strText was read from the text file using FSO which includes Carnage Return and\or LineFeed characters.

    TemplateOrg was read from the text file using Open for Input:LineInput method which doesn't include Carnage Return and\or LineFeed characters.

    strText doesn't contain exactly TemplateOrg and the Replace function doesn't find a match
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    04-06-2006
    Posts
    131

    Re: VBA Replace Function Not Working

    Oh, RIGHT!!!! You are a freaking genius AlphaFrog - thank you so much!!

    So - I tweaked the code to populate the Variable in the same way it does when it originally loads, and now it works like a charm.

    Please Login or Register  to view this content.
    Thanks again!!!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA Replace Function Not Working

    You're welcome. thanks for the feedback.

    FYI: This would read the text file including line-feed characters.
    Please Login or Register  to view this content.

+ 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. [SOLVED] Find/Replace function not working - please help :)
    By gregrach in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-15-2014, 11:16 AM
  2. [SOLVED] Doing a Find/Replace not working if "replace" text is too large
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2014, 02:52 PM
  3. find and replace function is not working correctly
    By rhino87 in forum Excel General
    Replies: 2
    Last Post: 10-10-2012, 04:16 PM
  4. My Find and Replace function in Excel is not working?
    By BPeach in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-19-2006, 03:55 PM
  5. Replace Function isn't working
    By Adam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2005, 05:00 PM

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