L
LeftyLeo via AccessMonster.com
Hi all,
I am not sure how to do the following in vba code: I want to copy the blank
excel template and name it, then fill the copy and finally to have the excel
spreadsheet open to view for the user. Here is the code I have that works
great to fill the template, but then I need to clear it and I am trying to
avoid this.
Private Sub cmdExport_Click()
Dim rec As DAO.Recordset
Dim objApp As Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim objRange As Excel.Range
Dim retVal As String
DoCmd.Hourglass True
'Open Excel workbook
Set objApp = New Excel.Application
Set objWorkbook = objApp.Workbooks.Open("C:\Documents and Settings\at74328\My
Documents\Promo1285\Enterprise Standard Entry Uploadnew.xls")
Set objSheet = objWorkbook.Sheets("Standard Entry")
'Export variables to Excel spreadsheet
objWorkbook.Sheets("Standard Entry").Range("A3").Value = "701"
objWorkbook.Sheets("Standard Entry").Range("B3").Value = sisCurYearFiscal
(Date)
objWorkbook.Sheets("Standard Entry").Range("C3").Value = Right(ClosingPd(Date)
, 2)
objWorkbook.Sheets("Standard Entry").Range("D3").Value = Right(ClosingPd(Date)
, 2) * 4
Set rec = CurrentDb.OpenRecordset("qryEJExport")
objSheet.Range("A8").CopyFromRecordset rec
'Close Workbook
objApp.Workbooks("Enterprise Standard Entry UploadNew.xls").Close SaveChanges:
=True
'Close Excel
objApp.Quit
Set objApp = Nothing
MsgBox "Export complete"
DoCmd.Hourglass False
End Sub
Can anyone help with this? I already searched the forum for an answer that
how I got this far. I love this site.
Thanks in advance,
Anna
I am not sure how to do the following in vba code: I want to copy the blank
excel template and name it, then fill the copy and finally to have the excel
spreadsheet open to view for the user. Here is the code I have that works
great to fill the template, but then I need to clear it and I am trying to
avoid this.
Private Sub cmdExport_Click()
Dim rec As DAO.Recordset
Dim objApp As Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim objRange As Excel.Range
Dim retVal As String
DoCmd.Hourglass True
'Open Excel workbook
Set objApp = New Excel.Application
Set objWorkbook = objApp.Workbooks.Open("C:\Documents and Settings\at74328\My
Documents\Promo1285\Enterprise Standard Entry Uploadnew.xls")
Set objSheet = objWorkbook.Sheets("Standard Entry")
'Export variables to Excel spreadsheet
objWorkbook.Sheets("Standard Entry").Range("A3").Value = "701"
objWorkbook.Sheets("Standard Entry").Range("B3").Value = sisCurYearFiscal
(Date)
objWorkbook.Sheets("Standard Entry").Range("C3").Value = Right(ClosingPd(Date)
, 2)
objWorkbook.Sheets("Standard Entry").Range("D3").Value = Right(ClosingPd(Date)
, 2) * 4
Set rec = CurrentDb.OpenRecordset("qryEJExport")
objSheet.Range("A8").CopyFromRecordset rec
'Close Workbook
objApp.Workbooks("Enterprise Standard Entry UploadNew.xls").Close SaveChanges:
=True
'Close Excel
objApp.Quit
Set objApp = Nothing
MsgBox "Export complete"
DoCmd.Hourglass False
End Sub
Can anyone help with this? I already searched the forum for an answer that
how I got this far. I love this site.
Thanks in advance,
Anna