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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access form to Excel

Status
Not open for further replies.

RufussMcGee

Technical User
Jan 7, 2005
117
US
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
 
I'd replace this:
Workbooks.Open
with this:
[!].[/!]Workbooks.Open

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You don't need to "select" you can reference.

excelobj.Application.Sheets("YourSheetName").Range("B2:B5").Font.Bold = True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top