I want to bold the title in excel sheet using a VBA

J

Jayani

Dear All,

I have done an Email automation program. In this case MS Access repor
output data to an Excel sheet. Then the program attach the Excel shee
to the email and send. All the programs have written in MS Acces
module. I want to bold the title in excel sheet using a VBA code whic
has written in the MS Access module.

Somebody please tell me how to do it...


Thanks in advance.
Jayan
 
D

Debra Dalgleish

You can add code to open and format the Excel workbook. For example:

'===========================
Sub FormatWorksheet()
' Set Reference to Microsoft Excel Object Library
' in VBE, choose Tools > References
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
strPath = "C:\"
strFile = "Test.xls"
strPathFile = strPath & strFile

'open Excel
Dim oXL As Excel.Application
Const ERR_APP_NOTRUNNING As Long = 429
On Error Resume Next
' Attempt to refeence running instance of Excel
Set oXL = GetObject(, "Excel.Application")
' If Excel isn't running, create a new instance
If Err = ERR_APP_NOTRUNNING Then
Set oXL = New Excel.Application
End If

oXL.Application.Visible = True
oXL.Application.Workbooks.Open strPathFile
Dim wb As Excel.Workbook
Set wb = oXL.Workbooks(strFile)

Dim ws As Excel.Worksheet
Set ws = wb.Sheets("Sheet1")

ws.Range("A1").Font.Bold = True
wb.Save
wb.Close
Set ws = Nothing
Set wb = Nothing
Set oXL = Nothing

End Sub
'===============================
 
J

Jayani

Dear Debra Dalgleish,

Thanks a lot. It is working and a great help. You helped me when I a
really in trouble. I will never forget it.

Thanks so much,

Regards,
Jayan
 
Top