Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

vb 6 writing to excel

This is the code that i use to write to an excel worksheet, my question is how can i set the cell properties so that the back ground color is used.
I've tried backcolor and it did not work.
        xlobj.Worksheets(1).Cells(Rows, 1).Value = rstPipe1.Fields("RecDate")
        xlobj.Worksheets(1).Cells(Rows, 2).Value = rstPipe1.Fields("ReferralContact")
        xlobj.Worksheets(1).Cells(Rows, 3).Value = rstPipe1.Fields("BusinessType")

xlobj.worksheets(1).range(A1:A14).backcolor = somecolor  
this does not work.

any suggestions.

thanx

0
jtjcomp
Asked:
jtjcomp
  • 6
  • 4
  • 3
1 Solution
 
samopalCommented:
set oRange = xlobj.worksheets(1).range(A1:A14).select
oRange.ColorIndex = YourColor

HTH
0
 
samopalCommented:
Sorry, last line should be

oRange.Interior.ColorIndex = YourColor

0
 
jtjcompAuthor Commented:
This is the line i used
    xlobj.Worksheets(1).Range("A1:N14").Interior.ColorIndex = vbBlue
and it gave me error 1004 unable to set the colorindex property of the interior class,


any suggestions as to why
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
samopalCommented:
Hmm... Try this:

xlobj.worksheets(1).range(A1:A14).select
xlobj.worksheets(1).selection.Interior.ColorIndex = vbBlue
 
I remember that I did it. But now I haven't Excel installed...
0
 
jtjcompAuthor Commented:
no, that did not work either.
0
 
jtjcompAuthor Commented:
That is not working i will reopen the question and see if there  are any other suggestions.
0
 
dalbelloCommented:
Try this
xlobj.Worksheets(1).Range("A1:A14").Interior.ColorIndex = 5

(0 = default, 1 = black, 2 = white,  3 = red, 4 = green, 5 = blue .... etc ... you can test )
0
 
jtjcompAuthor Commented:
Using a number for the colorindex work!
Thanx for your help, Both of you.

0
 
dalbelloCommented:
jtjcomp
I'm happy to help you.
Thank you.
0
 
dalbelloCommented:
jtjcomp
I'm happy to help you.
Thank you.
0
 
dalbelloCommented:
jtjcomp
I'm happy to help you.
Thank you.
0
 
dalbelloCommented:
jtjcomp
I'm happy to help you.
Thank you.
0
 
dalbelloCommented:
Thanks !
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now