[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Convert CSV to XLS including cell number formatting

Posted on 2008-06-10
Medium Priority
8,480 Views
Hi,

I use the code below to convert CSV files into XLS files, I call this using a batch file.

I have two problems,

1) One of my columns contains 13 digit numbers and in Excel these display like "4.71084E+12" and not "4710836936966" - because the cell format is General.  I would like to be able to specify the cell format is text

2) I need to explicitly pass the name of the input and output files in this VB script, I would like to be able to pass these as parameters when I call the VB in my batch file.

Any help greatly appreciated,

Rob

ps. I found this which may give some insight towards issuue 1 - http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_22650457.html?sfQueryTermInfo=1+csv+format+xl
dim oEx
set oEx=Createobject("Excel.Application")
oEx.Workbooks.Open "C:\testing\in.csv"
oEx.ActiveWorkbook.SaveAs "C:\testing\out.xls", -4143, , , False, False
oEx.Quit

0
Question by:arundelr
[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
• 2

Author Comment

ID: 21749784
The below code is doing what I need to clear up issue 1

I would still like to be able to pass the name of the input file to the VBS script rather than hard coding it.

Can anybody help with that?

i,.e. test.vbs -inputfile=c:\testing\in.csv

Thanks
Option Explicit

Dim fldr, f, file,strOrigFile, strFile, fso, strDirectory
Dim objExcel

strOrigFile = "C:\testing\in.csv"
'******************************************************
'CONVERTS THE FILE TO AN EXCEL FILE
'******************************************************
strFile = replace(strOrigFile,".csv",".xls")

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Open strOrigFile

objExcel.ActiveWorkbook.SaveAs strFile, -4143

objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

'******************************************************
'FORMAT THE EXCEL FILE AND SAVE IT
'******************************************************

objExcel.Workbooks.Open strFile

'Set the number format to zero D.P
objExcel.columns("A:A").numberformat="0"
objExcel.columns("C:C").numberformat="0"
objExcel.columns("D:D").numberformat="0"

objExcel.ActiveWorkbook.SaveAs strFile, -4143

objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
Set objExcel = Nothing

'msgbox "FINISHED!!!"

0

Accepted Solution

arundelr earned 0 total points
ID: 21751941
0

## Featured Post

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
###### Suggested Courses
Course of the Month12 days, 14 hours left to enroll