Solved

VbScript to Rename Column Header

Posted on 2011-09-16
8
1,360 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 48

Expert Comment

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

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 56

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 56

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

Industry Leaders: 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

635 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