mrfitness


I have a program that returns the value of a query and places it into excel. But I also entered a row of static text as headers. I want to bold the columns I want without doing a statement for each individual cell to be bolded. I cannot remember how to bold a selection of more than one cell in one command line.
i.e.
.sheets[esheet].cells(1,1).Value = "Contractno" &&COLUMN HEADER
.sheets[esheet].cells(1,1).font.fontStyle = 'Bold'
.sheets[esheet].cells(1,2).Value = "ProdName2010" &&COLUMN HEADER
.sheets[esheet].cells(1,2).font.fontStyle = 'Bold'
.sheets[esheet].cells(1,3).Value = "ProdCodePCL" &&COLUMN HEADER
.sheets[esheet].cells(1,3).font.fontStyle = 'Bold'
.sheets[esheet].cells(1,4).Value = "Total_rev" &&COLUMN HEADER
.sheets[esheet].cells(1,4).font.fontStyle = 'Bold'
.sheets[esheet].cells(1,5).Value = "Total_base" &&COLUMN HEADER
.sheets[esheet].cells(1,5).font.fontStyle = 'Bold'
.sheets[esheet].cells(1,6).Value = "Total_lst2010" &&COLUMN HEADER
.sheets[esheet].cells(1,6).font.fontStyle = 'Bold'
.sheets[esheet].cells(1,7).Value = "Ships" &&COLUMN HEADER
.sheets[esheet].cells(1,7).font.fontStyle = 'Bold'


I would like the fontStyle='Bold' to appear once for the values of '1,1' to '1,7'. I have tried using range, selecting cells first, and keep getting different errors. Any help Is it even possible to select a range of cells and then bolding that selection



Re: Using VFP to bold a row in excel

Naomi Nosonovsky


I think I posted a sample of my DBFToExcel function here.

Here is the relevant piece from this function:

Code Snippet

** Header font
WITH loSheet.RANGE(ALLTRIM(STR(m.lnLines + 1)) + ;
":" + ALLTRIM(STR(m.lnLines + m.lnoffset))).FONT
* .Color = Rgb(255,0,0)
.SIZE = 11
.Bold = .T.
.NAME = 'Tahoma'
ENDWITH






Re: Using VFP to bold a row in excel

Alex Feldstein

Something like this should work:

.sheets[esheet].Range("A1:G1").Select
.Selection.Font.Bold = .T.






Re: Using VFP to bold a row in excel

mrfitness

You would think it would work but I get the error 'Unable to get the select property of the range class"




Re: Using VFP to bold a row in excel

mrfitness

I did use a loop below to do the job, but I would still prefer doing it with a selection line.
for x = 1 to 63
loExcelTemplate.sheets[esheet].cells(1,x).font.fontStyle = 'Bold'
endfor

Is this the best way Any way more efficient




Re: Using VFP to bold a row in excel

mrfitness

I get an error on the range line: 'operator type mismatch'




Re: Using VFP to bold a row in excel

Naomi Nosonovsky

I guess you didn't use correct values for variables. Just use Range("A1:G1") then. You don't need to select.



Re: Using VFP to bold a row in excel

mrfitness

You're right I didn't need the SELECT, but the bold didn't work (although there were no errors)




Re: Using VFP to bold a row in excel

Naomi Nosonovsky

I'm not sure then right now. I know that the code in my function (DBFToExcel) works fine and I have nice header font as well as some other extra features (Totals in green, etc.)



Re: Using VFP to bold a row in excel

mrfitness

Alex I removed the 'Select' to avoid errors. Unfortunately the bold part didn't work although no errors occurred in the program. Any ideas

Alex Feldstein wrote:

Something like this should work:

.sheets[esheet].Range("A1:G1").Select
.Selection.Font.Bold = .T.





Re: Using VFP to bold a row in excel

Naomi Nosonovsky

BTW, strange that it doesn't work. See http://fox.wikis.com/wc.dll Wiki~ExcelAutomation there is an example of selecting a range just using range(..).Select syntax



Re: Using VFP to bold a row in excel

mrfitness

Yes that link helped, but some examples I tried still didn't work with the bold even without errors in the program. I tried both .Selection.Font.Bold = .T. and .Selection.Font.Bold = "True"




Re: Using VFP to bold a row in excel

Naomi Nosonovsky

Did you try

loSheet.RANGE('A1:G1').FONT.Bold = .t. as in my sample





Re: Using VFP to bold a row in excel

mrfitness

I get an 'unknown name' error




Re: Using VFP to bold a row in excel

Alex Feldstein

mrfitness wrote:
Alex I removed the 'Select' to avoid errors. Unfortunately the bold part didn't work although no errors occurred in the program. Any ideas

Try this little test program:


Code Snippet
loSheet=loExcel.ActiveSheet
loSheet.Range("A1").Select
loExcel.ActiveCell.FormulaR1C1="1"
loSheet.Range("B1").Select
loExcel.ActiveCell.FormulaR1C1="2"
loSheet.Range("C1").Select
loSheet.Range("A1:B1").Select
loExcel.Selection.Font.Bold = .T.