Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bolding Font in VBA

Status
Not open for further replies.

Bwlep

Programmer
Mar 27, 2008
4
US
I am using VBA and need to change the font for UserName to bold and maybe a different size. Is there a way to do this?

"SELECT user.user_name as UserName, log.log_date INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheet & "] FROM user INNER JOIN log ON user.user_id = log.user_id
 




Hi,

So where are you going to place this value from your query? In a cell on a sheet? In some kind of a control?

Please be more specific.

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
In a cell on a worksheet. Can I format in VBA before exporting to worksheet?
 
A starting point:
Code:
With yourCellReference.Font
  .Bold = True
  .Size = 12
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
A macro recorder will give you a good start
Code:
    With Range("A1:X1").Font
        .Name = "Arial"
        .Size = 11
        .Bold = True
    End With
    Range("A1") = "Some text or value"

good luck

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
That looks like what I need, but can i get an example of combining it with the SQL statement... I am not sure how it fits together....
 



If you are using ADO or DAO, you can use the CopyFromRecordset method to put your data on a sheet, like...
Code:
Activesheet.Cells(1,1).copyfromrecordset rst
where rst is your recordset.

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
Skip, this is WAAAY out of my area of knowledge, but would that not assume the format structure is IN the recordset?

Is that a safe assumption here?

bwlep, as stated, this is way out of my area, but is not a SQL statement essentially a request for data, given as a string? So how that data is displayed in the requesting application is either:

1. formatted by elements of the data (Skip's copyfromrecordset)

2. or not formatted. In which case the formatting is a function of the receiving application.

If it is #2, then the formatting instructions are executed instructions of the receiving application, and not the SQL statement.

"Can I format in VBA before exporting to worksheet?"

Both PHV and CluLessChris suggestions are independent of the SQL statement. However, they could run before it (your question is answered Yes), or after (your question is answered No).

If Skip's suggestion works for you, then your question is moot, as there would no no formatting actually done by VBA instructions. The format would be passed, kind of like a parameter. I guess more properly, the format would be a property.

faq219-2884

Gerry
My paintings and sculpture
 




"Can I format in VBA before exporting to worksheet?"

In VBA, you muse manipulate the appropriate OBJECTS -- Excel objects and ADO objects.

Once the query has been executed and the recordset returned to the recordset object, then you have to place the data that is in the recordset on a worksheet object. As far as I know, there is no formatting available in ADO objects.

But, because you must reference the range that the CopyFromRecordset will return the data to, at the same time, you can specify whatever formatting you choose to the result range.

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
You cannot format data in SQL (other than setting data types).

You do formatting AFTER the data is returned to the host application

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top