Solved

VbScript to Rename Column Header

Posted on 2011-09-16
8
1,241 Views
Last Modified: 2012-08-14
is there a Vb Script out there that can rename a Column header

for example the Script would rename the row header in column B from 123 to Hello_World

???

File attache with Columb Be header 123  to make sure im not communicating poorly :)

File1.csv
0
Comment
Question by:plusone3055
  • 4
  • 3
8 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 36551438
Record a macro doing it yourself and then edit/cut/paste the macro.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36551537
Will the file to be processed be in a CSV format, or in an XLS format?

~bp
0
 
LVL 22

Author Comment

by:plusone3055
ID: 36551848
I've requested that this question be deleted for the following reason:

I found another solution that will not require a macro or a VB Script. I changed something in my query that was producing this CSV file Thank you all
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 54

Expert Comment

by:Bill Prew
ID: 36551603
Great, always the best approach when you can adjust at the source.

~bp
0
 
LVL 22

Author Comment

by:plusone3055
ID: 36551707
I was wrong that will only work in one place
I still need it :(

Floor is open

0
 
LVL 22

Author Comment

by:plusone3055
ID: 36551709
billprew
CSV format
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36551849
Here's a quick example of this, adjust the replace logic as needed.  Save as a VBS file, and run like this:

cscript EE27312667.vbs EE27312667.csv EE27312667.new
or
cscript EE27312667.vbs EE27312667.csv

In the first case the first file will be read, and the updated version written to a new file specified by the second parm.  In the second example the initial file will be overwritten with the changed version.

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
  sInfile = WScript.Arguments(0)
Else
  WScript.Echo "No filename specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  sOutfile = WScript.Arguments(1)
Else
  sOutfile = sInfile
End If

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Read entire input file into a variable and close it
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
oInfile.Close
Set oInfile = Nothing

' Replace commas (,) with pipes (|)
sData = Replace(sData, ",123,", ",Hello_World,", 1, 1, 1)

' Write file with any changes made
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
oOutfile.Write(sData)
oOutfile.Close
Set oOutfile = Nothing

' Cleanup and end
Set oFSO = Nothing
Wscript.Quit

Open in new window

~bp
0
 
LVL 22

Author Closing Comment

by:plusone3055
ID: 36554784
just what was needed :)
many thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question