Murray Brown
asked on
Access VBA Excel bold not working
Hi
In the following Access VBA code the only line that doesn't work is
Worksheet.Selection.Font.B old = True
Public Function ExcelExportAndFormat(ByVal CRecordset As DAO.Recordset, ByVal CSheetName As String) As Object
On Local Error Resume Next
Dim Excel As Object ' Excel.Application
Dim Workbook As Object ' Excel.Workbook
Dim Worksheet As Object ' Excel.Worksheet
Dim Count As Long
Set ExcelExportAndFormat = Nothing
Set Excel = CreateObject("Excel.Applic ation")
Set Workbook = Excel.Workbooks.Add
Set Worksheet = Workbook.Sheets(1)
Worksheet.Name = CSheetName
For Count = 0 To CRecordset.Fields.Count - 1
Worksheet.Range("A1").Offs et(, Count).value = CStr(CRecordset.Fields(Cou nt).Name)
Next Count
Worksheet.Range("A2").Copy FromRecord set CRecordset
Worksheet.Cells.EntireColu mn.AutoFit
Worksheet.Rows("1:1").Sele ct
Worksheet.Selection.Font.B old = True
Set ExcelExportAndFormat = Worksheet
Excel.Visible = True
Set Worksheet = Nothing
Set Workbook = Nothing
Set Excel = Nothing
End Function
In the following Access VBA code the only line that doesn't work is
Worksheet.Selection.Font.B
Public Function ExcelExportAndFormat(ByVal
On Local Error Resume Next
Dim Excel As Object ' Excel.Application
Dim Workbook As Object ' Excel.Workbook
Dim Worksheet As Object ' Excel.Worksheet
Dim Count As Long
Set ExcelExportAndFormat = Nothing
Set Excel = CreateObject("Excel.Applic
Set Workbook = Excel.Workbooks.Add
Set Worksheet = Workbook.Sheets(1)
Worksheet.Name = CSheetName
For Count = 0 To CRecordset.Fields.Count - 1
Worksheet.Range("A1").Offs
Next Count
Worksheet.Range("A2").Copy
Worksheet.Cells.EntireColu
Worksheet.Rows("1:1").Sele
Worksheet.Selection.Font.B
Set ExcelExportAndFormat = Worksheet
Excel.Visible = True
Set Worksheet = Nothing
Set Workbook = Nothing
Set Excel = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER