Solved

Convert CSV to XLS including cell number formatting

Posted on 2008-06-10
2
8,446 Views
Last Modified: 2008-06-10
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

Open in new window

0
Comment
Question by:arundelr
  • 2
2 Comments
 

Author Comment

by:arundelr
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.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs strFile, -4143
 
objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.Close
objExcel.DisplayAlerts = False
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.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs strFile, -4143
 
objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.Close
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
 
'msgbox "FINISHED!!!"

Open in new window

0
 

Accepted Solution

by:
arundelr earned 0 total points
ID: 21751941
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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