Exporting access to an excel template

RRMESLTD

New Member
Joined
Jul 21, 2004
Messages
24
Hi All,
Can anyone help, With the help of this forum I have completed a certain task – but the’ icing on the cake’ would be my last query.
Does anyone know a way where I when I convert my access database to excel , I can place the excel data into a excel template as a separate worksheet.

Basically I have an access database which shows ‘open/overdue orders’ with our suppliers which we will send out via email. My current macro converts that data to excel as a lotus notes attachment , but you only have a ‘limited no of characters ‘ within the ‘message text’ field in the macro.

My excel template I wish to add the converted access data has a covering worksheet with company logo, contact details & a standard message & I would like the actual data to go as a worksheet within the excel spreadsheet(a page 2 if you like), or if easier, all on the 1 worksheet but below the company logo & standard message.

Any help, much appreciated
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How about this for a start:

Code:
Sub ExportToXLTemplate()
Dim xlApp As Excel.Application
Dim xlBook As Workbook
Dim xlSheet As Worksheet
Dim dbs As Database
Dim rst As Recordset

Set xlApp = GetObject(, "Excel.Application")
Set xlBook = xlApp.Workbooks.Add("c:\MyTemplate")

xlBook.SaveAs "C:\MyNewWorkbook.xls"
xlBook.Close

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "MyTable", "C:\MyNewWorkBook.xls"


Set xlBook = Nothing
Set xlApp = Nothing

End Sub

Change file names/locations as appropriate.
 
Upvote 0
well thnaks to everyone i have my query sorted, if anyone needs help please see below,

just change the details to reflect your own file names..

the query exports from access, to an excel template(OR AS SHEET 2 IN A WORK BOOK) - then prepares a draft email in your inbox (lotus notes)


Sub ExportToXLTemplate()
'Dim xlApp As excel.Application
'Dim xlBook As Workbook
'Dim xlSheet As Worksheet
'Dim dbs As Database
'Dim rst As Recordset

'Set xlApp = GetObject(, excel.Application)
'Set xlBook = xlApp.Workbooks.Add("O:\Purchasing\PURCH\OS Orders Trial Data\OrderProgress.xlt")
'xlBook = GetObject("O:\Purchasing\PURCH\OS Orders Trial Data\OrderProgress1.xls")

'xlBook.SaveAs "O:\Purchasing\PURCH\OS Orders Trial Data\openorders.xls"
'xlBook.Close

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "Open Orders - By Supplier Code", "O:\Purchasing\PURCH\OS Orders Trial Data\OrderProgress1.xls"

'DoCmd.SendObject (file,"")
'DoCmd.SendObject
Call SendNotesMail("Order Progress", "O:\Purchasing\PURCH\OS Orders Trial Data\OrderProgress1.xls", "", "", False)
Set xlBook = Nothing
Set xlApp = Nothing

End Sub

Sub af()



End Sub


'Public Sub SendNotesMail(Subject as string, attachment as string,
'recipient as string, bodytext as string,saveit as Boolean)
'This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.
Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Next line only works with 5.x and above. Replace password with your password
'Session.Initialize ("pswd")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string or using above password you can use other mailboxes.
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
'MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
'MailDoc.SEND 0, Recipient
MailDoc.PutInFolder ("Other\Draft")
xxx = MailDoc.save(False, False)
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,913
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top