Solved

How to change the cell format to text in xls using vb script?

Posted on 2008-10-27
1
742 Views
Last Modified: 2008-11-16
I have written following code attached alongwith in vb script, now I want to change the column or cell format to text of data in column 3 since I want to attach a leading 0 to the data "val" in the output xls in which I am writting data. In the code "val", "fn" & "ln" are some string data.

Please give me a solution to this.

Regards,
Pranjal


dim xls_sheet,xls_app
set xls_app=createobject("Excel.Application")
Set xlwb = xls_app.Workbooks.Open(jcdest & "jc_template1.xls") 
	set xls_sheet = xlwb.sheets("Sheet1")
xls_sheet.ActiveSheet.cells(r,3)= val
		xls_sheet.ActiveSheet.cells(r,2)= trim(fn)
		xls_sheet.ActiveSheet.cells(r,1)= trim(ln)

Open in new window

0
Comment
Question by:pranjal_ds
[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
1 Comment
 
LVL 18

Accepted Solution

by:
exx1976 earned 250 total points
ID: 22817260
The code below can be called like this:

TextFormat 1,"A1:G17"

Enjoy!
Sub TextFormat(sheetNumber, cells)
	Dim arr()
         Dim sheet, oRange
         On Error Resume Next
	arr = Split(cells,":",-1,1)
	Set sheet = xls_app.ActiveWorkBook.Worksheets(sheetNumber)
	If arr(0) = arr(1) Then
		Set oRange = sheet.Range(arr(0))
	Else
		Set oRange = sheet.Range(arr(0), arr(1))
	End If
	oRange.NumberFormat = "@"
         Set sheet = nothing
         Set oRange = nothing
End Sub

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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