Solved

VbScript to Rename Column Header

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

Expert Comment

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

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
 
LVL 51

Expert Comment

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

~bp
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 51

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now