Append String to rows of text file

March 4, 2010 at 06:18:20
Specs: Windows XP
I am trying to get input from a user of the file
name and then append a string to the end of
each row of the file name the user puts into it.

See More: Append String to rows of text file

Report •

March 4, 2010 at 10:11:40
How about this?

As written, it displays the "new" File Name but it could be altered to do whatever fits your needs.

Am I close?

Sub GetFileName()
Dim myString, userFileName, myFilename As String
'Initialize myString variable
  myString = "Test"
'Get File Name from user
   userFileName = Application.GetOpenFilename
'Append myString to File Name before .xls
    myFilename = Left(userFileName, Len(userFileName) - 4) _
                 & myString & ".xls"
'Display new File Name
  MsgBox myFilename
End Sub

Note: If used with both .xls and .xlsx files some minor modifications will be required. I'm just trying to see if I am on the right track.

Report •

March 4, 2010 at 11:46:29
Oh, my mistake i Meant for Batch: this is what I ended up

@echo off
Rem Delete any leftovers from last attempt
if exist 2010.dat del /q 2010.dat
if exist temp.txt del /q temp.txt

Rem Gather information from user
set /p tstamptrans=1) Please enter String to delete (14 chars
set /p Original=2) Please enter File Name (monkey.txt for

Rem settings for progress bar
set i=1
(Set /P j=Processing Conversion) < NUL

Rem loop to read in file and output temp file after removing
@echo off > temp.txt & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (%Original%) do (
set str=%%a
set str=!str:%tstamptrans%=!

Rem progress bar piece
call :DisplayProgressBar %i%
set /a i = i + 1

echo !str!>> temp.txt

Rem Adds 14 spaces to end of each row
for /f "delims=" %%l in (temp.txt) Do (
echo %%l >> 2010.dat

Clean up temp file
if exist temp.txt del /q temp.txt

(Set /P j=.) < NUL
title Processing Please do not close
exit /b

Report •

Related Solutions

Ask Question