Formatting exported Excel sheet

Malcy

Registered User.
Local time
Today, 11:18
Joined
Mar 25, 2003
Messages
584
Hi
I am struggling with an exported Excel sheet that is used to allow suppliers to enter information that is then uploaded back into my db app. The problem is with one field in Column H.
In Access it is a text format in that it contains a 7 digit number where the first digit may be a zero. This exports into the spreadsheet fine, but ...
If the supplier needs to change this code and the new code starts with a leading zero then Excel chops off that leading zero and so gives me a false code.
What I need to do programatically is to set the format for the cells in column H specifically to text.
I have tried rather optimistically (but it doesn't like it - so I have commented it out)
Code:
' Set the background to yellow for columns G & H
   oSheet.Columns("G:H").Interior.ColorIndex = 6
   oSheet.Columns("A:D").Interior.ColorIndex = 15
   
' Set the cell format to text for Column H
'    oSheet.Columns("H").Format.Text
I have not included the preceeding and following code for the sake of simplicity.
I have tried searching the forum and also google to see if I can get the right key words/syntax but to no avail. I have tried a number of variants but none seem to work.
Can anyone help me on this one?
Thanks in anticipation
Best wishes
 
Depending on what suits your purpose best, you may for instance try

oSheet.Columns("H").Numberformat = "@" ' text format

oSheet.Columns("H").Numberformat = "0000000" ' numeric
' 7 digits, or show leading digits
 
Magic Roy
I used
oSheet.Columns("H").Numberformat = "0000000"
and it worked a treat.
Help much appreciated. Thanks again
 

Users who are viewing this thread

Back
Top Bottom