|
-
May 30th, 2002, 10:56 PM
#1
Thread Starter
PowerPoster
how to bold rows/cells in excel from VB
I have a VB app that populates an excel spreadsheet very successfully, but now I want to do some formatiing and haven't a clue how.
I've done
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlDataSheet As Excel.Worksheet
Dim xlSumSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open _
("c:\gandalf\template.xls", , True)
Set xlDataSheet = xlBook.Worksheets("Data")
Set xlSumSheet = xlBook.Worksheets("Sums")
to open up the excel file and a couple of worksheets, and I push data into them with no problem and can close and save, so my content is where I want it and now I'm interested in cosmetics.
I'd like to have row 3 in the "Data" sheet become all bold, and I'd like cell (5,2) in the Sums sheet to become bold
I'd appreciate any guidance.
-
May 31st, 2002, 02:02 AM
#2
Range("E6:E10").Select
Selection.Font.Bold = True
change the cell coordinates
-
May 31st, 2002, 04:03 AM
#3
You need to precede Khalik's code with the appropriate objects, in your current example it would be:
VB Code:
xlDataSheet.Range("3:3").Select
xlApp.Selection.Font.Bold = True
xlSumSheet.Range("E2").Select
xlApp.Selection.Font.Bold = True
-
May 31st, 2002, 07:14 AM
#4
Thread Starter
PowerPoster
still can't get range to go bold
sure sounds like the right thing to do, and I apprecieate the guidance, but I can't get it to work:
xlDataSheet.Range("B2:B20").Select
gets me "select method of range class failed"
so does
xlDataSheet.Range("2:2").Select
and
xlDataSheet.Range("2:20").Select
on the other hand,
xlDataSheet.Range("2").Select
gets me "method range of objext worksheet failed"
clearly I'm missing something fundamental, but have no idea what it is.
-
May 31st, 2002, 07:28 AM
#5
the error "method range of object worksheet failed" means you have specified an invalid range (to select a row you need "n:n", where n is the row number). The other error means (in this situation at least) that you cannot select ANYTHING on that sheet at the moment.
you may have to get the worksheet activated first, eg:
xlDataSheet.Activate
-
May 31st, 2002, 07:35 AM
#6
Thread Starter
PowerPoster
activate was it, Si.
thanks very much for the help !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|