By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

Exporting and formating Excel Spreadsheet from VB6

P: 7
Hi, I have the following code to export to a new Excel spreadsheet. What I need to do is format the cells. How can I change the font, font size and colour and most importantly the cells background color.
Thanks in advance.

Private Sub Command1_Click()
Dim appxl
Dim Book As Excel.Workbooks
Dim Wsheet As Excel.Worksheet
FileName = "c:\new.xls"
Set appxl = CreateObject("Excel.Application")
Set Book = appxl.Workbooks
Set Wsheet = Book.Add.Worksheets(1)
appxl.Visible = True

Wsheet.Cells(1, 1) = Text1.Text

End Sub
Dec 27 '07 #1
Share this Question
Share on Google+
1 Reply

P: 180
use following code to format cells

Dim cellRange As String
cellRange = ws.Cells(1, 1).Address
cellRange = cellRange & ":" & ws.Cells(intStartRow, intCol + 1).Address
With Selection
.Font.Bold = True
End With

similarly you can apply other settings such as color etc. the easiest way is, open microsoft excel. start macro recording then do whatever you want in the sheet. then open the macro in visual basic editor. all the code will be there. you can use this code in your application

manpreet singh dhillon hoshiarpur
Dec 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.