Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2011, 09:50 AM
Registered User
 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing Text in .txt file

They way my macro is set up now it will delete a serial_number.txt file and then create a new one with the value that was in the old file + 1 so for example if the old file said 1 the new file would say 2. I want to change this to replace text rather than delete a file each time this is ran. One problem I ran into when doing this was permission was not granted and this file will be sent to multiple computers and if one of them does not have permission then it won't work for them. Any ideas on how to replace text? I can do a find and replace method by referencing the cells for my variables. so say I had sn = range("'Config'!B6") then I could just go find sn, replace sn + 1 not sure if that helps but I will be searching some more but have not had any luck so far :/ Hope someone can help me! Thanks


SOLUTION: http://forums.devx.com/showthread.php?t=130375
I used the code posted there. code by Greg DeBacker

Last edited by Elevate08; May 17th, 2011 at 11:50 AM.. Reason: solution
 
Old May 17th, 2011, 10:41 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 171
Thanks: 0
Thanked 14 Times in 14 Posts
Default

I believe if you open a file for write access without the Append parameter, it just overwrites the old file. In other words, there should be no reason for deleting the old file first.

I don't use read/write that often. Is the permission problem an operating system problem or is it an excel issue? If it's excel, it may be that you're opening the file for read access then trying to write to it in that mode, which won't work. If you need to open the file to find out what the serial number is, do so, then close it and open it in write mode (with no Append parameter).

Hope that helps :)

Last edited by mtranchi; May 17th, 2011 at 10:46 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to import a text file w/t changing row order lxj034000 SQL Server 2000 1 July 12th, 2007 07:04 AM
Changing between bold and plain text in a text box funkybuddha Access 2 January 3rd, 2006 10:15 AM
parsing a changing text file on the fly Kannkor VB How-To 0 November 14th, 2005 01:47 AM
changing Text source file names rjjhome SQL Server DTS 1 August 18th, 2004 02:27 PM
Read data from a text file (*.txt) adriant42 Excel VBA 2 June 4th, 2004 06:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.