RufussMcGee
Technical User
Found this code to export Access form data to excel. I added a few lines to open an existing excel file, the probelm being it only works once; excel is left in the computer memory even after clsoing excel and cannot get it to clear. My second question is how do you goto a specfic sheet in excel?
Many Thanks.
Private Sub BuildSheet_Click()
Dim excelobj As New Excel.Application
excelobj.Visible = True
With excelobj
'Add a workbook.
.Workbooks.Add
ChDir "C:\LCD\Programming"
Workbooks.Open Filename:="C:\LCD\Programming\PROJECT.XLS"
.Cells(1, 2).Value = Me!SalesRep
.Cells(2, 2).Value = Me!FirstQ
.Cells(3, 2).Value = Me!SecondQ
.Cells(4, 2).Value = Me!ThirdQ
.Cells(5, 2).Value = Me!FourthQ
.Columns("B:B").ColumnWidth = 13.14
.Range("B1:B1").Select
.Selection.Font.Bold = True
.Range("B2:B5").Select
.Selection.NumberFormat = "$#,##0.00"
.Range("B2:B5").Select
.Selection.Font.Italic = True
MsgBox "Switch to Excel in the taskbar, check and save results."
'.ActiveWorkbook.Close SaveChanges:=False
.Quit
End With
Set excelobj = Nothing
End Sub
Many Thanks.
Private Sub BuildSheet_Click()
Dim excelobj As New Excel.Application
excelobj.Visible = True
With excelobj
'Add a workbook.
.Workbooks.Add
ChDir "C:\LCD\Programming"
Workbooks.Open Filename:="C:\LCD\Programming\PROJECT.XLS"
.Cells(1, 2).Value = Me!SalesRep
.Cells(2, 2).Value = Me!FirstQ
.Cells(3, 2).Value = Me!SecondQ
.Cells(4, 2).Value = Me!ThirdQ
.Cells(5, 2).Value = Me!FourthQ
.Columns("B:B").ColumnWidth = 13.14
.Range("B1:B1").Select
.Selection.Font.Bold = True
.Range("B2:B5").Select
.Selection.NumberFormat = "$#,##0.00"
.Range("B2:B5").Select
.Selection.Font.Italic = True
MsgBox "Switch to Excel in the taskbar, check and save results."
'.ActiveWorkbook.Close SaveChanges:=False
.Quit
End With
Set excelobj = Nothing
End Sub