Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VbScript to Rename Column Header

Posted on 2011-09-16
8
Medium Priority
?
1,405 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 49

Expert Comment

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

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 57

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 57

Accepted Solution

by:
Bill Prew earned 2000 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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

722 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