MAcro or BAtch file to change cell format

jbalbo

New Member
Joined
Jul 23, 2014
Messages
6
Hi
I receive a file from SQL where all the columns are formatted as "General" I would like to write a batch file to change them all to Text
I found this bs file that changes the font, but what would I use to change the format?
Thanks
'launch Excel and open file
Set xlObj = CreateObject("Excel.Application")
Set xlFile = xlObj.WorkBooks.Open("c:\temp\filename.xls")
'turn off screen alerts
xlObj.Application.DisplayAlerts = False
'loop through sheets
For Each Worksheet In xlFile.Worksheets
'change sheet to desired worksheet name
If Worksheet.Name = "SheetToRename" Then
Worksheet.Name = "NewName"
End If
'change all sheets to desired font
With Worksheet.Cells.Font
.Name = "Verdana"
.Size = 12
End With
Next
'save, close, then quit
xlFile.Close True
xlObj.Quit
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try ...

Rich (BB code):
Set xlObj = CreateObject("Excel.Application")
Set xlFile = xlObj.Workbooks.Open("c:\temp\filename.xls")
'turn off screen alerts
xlObj.Application.DisplayAlerts = False
'loop through sheets
For Each Worksheet In xlFile.Worksheets
'change sheet to desired worksheet name
If Worksheet.Name = "SheetToRename" Then
Worksheet.Name = "NewName"
End If
'change all sheets to desired font
With Worksheet.Cells.Font
.Name = "Verdana"
.Size = 12
.NumberFormat = "@"
End With
Next
'save, close, then quit
xlFile.Close True
xlObj.Quit
 
Upvote 0
Thanks... Let me give it a try...
Sorry, for the dumb questions.. but would I run this like a batch file?
 
Upvote 0
No, actually it's written as a VB Script file, so if you're on Windows (would suggest updating your profile ...) it should run from File Explorer, provided it has a .VBS extension name.
 
Upvote 0
Thanks for getting back, that didn't work, but maybe if II tell you what I really need, it might help :)
Sorry, not too good at this.
I have a file cald filename.xlsx it comes to me with the number format as "General", I need the script to open the Excel file, change the Number format to "Text", save and close
 
Upvote 0
Sorry, didn't look closely and made a mistake. The red colored line in my previous post should have looked like this:
VBA Code:
.Parent.NumberFormat = "@"
 
Upvote 0
Solution
You are welcome & thanks for letting me know.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top