Solved

VbScript to Rename Column Header

Posted on 2011-09-16
8
1,294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 47

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

710 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