473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Excel/Word Export

Is it possible to export data to Word and Excel documents and, once it is exported to the required document type, format it from within Excel?
May 24 '07 #1
10 3089
NeoPa
32,556 Expert Mod 16PB
Is it possible to export data to Word and Excel documents and, once it is exported to the required document type, format it from within Excel?
When you say "format it from within Excel?", do you mean "format it from within the related application?"?
If so, then yes. BUT, it is quite advanced and requires Application Automation.
I know very little about Word coding, but I imagine that whichever you're using, you could use the clipboard in your code to transfer the data across.
May 25 '07 #2
Basically I have a bunch of forms that will be stored in a database by project. I need to be able to export these forms to word or excel in order to send them to other people via E-Mail. I need to export them, maintaining their formatting, though, so that the people on the other end can simply print them out.

More specifically, here is what I would like to do, step by step:

1) User fills out form, clicks print, chooses E-Mail as Excel Document
2) Create an instance of an Excel object.
3) Format the form (such as setting the background colour of cells, changing the width of columns and height of rows, adding borders to cells, adding the base text, adding tables, formatting those tables, setting alignment, et cetera).
4) Export the information from the database table to the appropriate spaces on the newly formatted form.
5) Save the form to a temporary location
6 Create a new Outlook E-Mail instance
7) Attach the temporary file to the E-Mail
8) Attach a Subject line to the E-Mail
9) Add a list of standard recipients to the new E-Mail

Steps 2-4 are the ones that I have no earthly idea how to do. If all of this is possible, I just need the basic idea behind it and I can figure out how to make it all work together. (More specifically, what classes/sub-routines and what functions are used in this process via VBA.) Unfortunately the entire thing absolutely MUST be done in Access. If this is not possible, I'll hack something together to make it happen, but I'd prefer not to have to do that.

Thanks

(BTW, that article is a good start to what I need, but I need something perhaps a bit more in depth)
May 29 '07 #3
LacrosseB0ss
113 100+
I had a prof tell me once "If you can think about it, you can program it". The trick is it depends how complex you want to get. The export parts aren't really that difficult with the right references added and such (off hand I forget what they are) but the Excel formatting could hurt your brain.

Is it possible to export data to Word and Excel documents and, once it is exported to the required document type, format it from within Excel?
May 29 '07 #4
NeoPa
32,556 Expert Mod 16PB
(BTW, that article is a good start to what I need, but I need something perhaps a bit more in depth)
The article simply introduces you to the concept of Application Automation (with some how-to's thrown in). It doesn't deal with Excel & Word & Outlook & ... etc. This is, after all, an Access forum. I can help with specific questions in Excel (I'm certainly not going to code your project for you), but the Outlook & Word areas are foreign to me. That stuff you'll have to research.
The concept of Application Automation does not include expertise in all the various applications that are able to be programmed in this way.
May 29 '07 #5
I found the information I was looking for. This is what I came up with, for anyone who would like to use this feature in their programs:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ' Requires a Reference to Microsoft Excel 8.0 Object Library or Higher
  3. ' In VBE, goto Tools->References... and select it from the list
  4.  
  5. Private Sub ExportToExcel()
  6.  
  7.     ' Variable Declarations
  8.     Dim objExcel As Excel.Application
  9.  
  10.     ' If Excel is open, use GetObject, otherwise create a new Excel object
  11.     ' Error 429 is Application Not Running
  12.     On Error Resume Next
  13.     Set objExcel = GetObject(, "Excel.Application")
  14.     If Err = 429 Then Set objExcel = New Excel.Application
  15.  
  16.     With objExcel
  17.         ' Adds a new workbook to the Excel environment
  18.         .Workbooks.Add
  19.  
  20.     ' Excel VBA Code goes here
  21.  
  22.     ' Causes the Excel window to become visible
  23.         .Visible = True
  24.     End With
  25. End Sub
  26.  
  27.  
And just for kicks, here is the code to send a new E-mail via Outlook:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub ExportToOutlook()
  3.  
  4. ' Requires A References to the Microsoft Outlook Object Library
  5. ' in VBE, select Tools->References, and ensure it is checked
  6.  
  7. Private Sub ExportToOutlook()
  8.  
  9.     ' Variable Declaration
  10.     Dim objOutlook as Object
  11.     Dim objEMail as Object
  12.  
  13.     ' If Outlook is open, use GetObject, otherwise open Outlook
  14.     Set objOutlook = GetObject(, "Outlook.Application")
  15.     If objOutlook Is Nothing Then Set objOutlook = CreateObject("Outlook.Application")
  16.  
  17.     ' Creates a new e-mail
  18.     Set objEMail = objOutlook.CreateItem(0)
  19.     With objEMail
  20.  
  21.         ' Adds To Recipient
  22.         Set ToContact = .Recipients.Add("Me@Gmail.Com")
  23.  
  24.         ' Adds CC recipient
  25.         ToContact.Type = olCC
  26.         Set ToContact = .Recipients.Add("You@Gmail.com")
  27.  
  28.         ' Sets the Subject
  29.         .Subject = "Service Report 1234"
  30.  
  31.         ' Sets the Body
  32.         .Body = "Attached herein are the Reports"
  33.  
  34.         ' Adds attachment
  35.         .Attachments.Add "c:\Service Report 1234", olByValue, , "Service Report"
  36.  
  37.         ' Embeds attachment
  38.         .Attachments.Add "c:\JoeBob.gif", olEmbeddedItem, , "Joe Bob's Picture"
  39.  
  40.         ' Receipt upon delivery
  41.         .OriginatorDeliveryReportRequested = True
  42.  
  43.         ' Recipt upon read
  44.         .ReadReceiptRequested = True
  45.  
  46.         ' Displays the E-Mail
  47.         .Display
  48.  
  49.         ' Sends the E-Mail
  50.         .Send
  51.  
  52.         ' Saves a Draft of the E-Mail
  53.         .Save                                        
  54.     End With
  55.  
  56. End Sub
  57.  
  58.  
  59.  
Lastly, I wouldn't expect you to code my entire project. I have close to 100 different forms that need to be linked together via a database and exported to excel/word then e-mailed. This is quite a large undertaking. At the moment the forms and database are all working fine except for export to excel and e-mail functions of each one that requires them. Now that I have this I can do almost everything I need to do.
May 30 '07 #6
NeoPa
32,556 Expert Mod 16PB
Lastly, I wouldn't expect you to code my entire project. I have close to 100 different forms that need to be linked together via a database and exported to excel/word then e-mailed. This is quite a large undertaking. At the moment the forms and database are all working fine except for export to excel and e-mail functions of each one that requires them. Now that I have this I can do almost everything I need to do.
First of all, let me congratulate you for getting past your earlier problems.
The 'Entire Project' bit was about how you asked the question. Scope is very important here, and you can get a lot more help if you break it down into more bite-sized chunks. Larger scoped questions can be seen as expecting some of the leg-work be done for you (so many OPs do I'm afraid).
Be that as it may, your code may prove vey helpful to others (as it hapens) and I'm going to try to add your two example pieces of code into the article I linked earlier. I fully expect to use the Outlook part myself too, so my gratitude is due for that also. All in all, a lot of benefit from your last post, so thanks for that.
As a sort of 'quid pro quo', if you need help formatting (or doing other clever things in Excel), I may well be able to help. Post any (bite-sized) questions in this thread so that I see the updates (I've registered in this thread so will get any updates). I don't get to see all the new threads anymore, as there are simply too many for me to cope with usually :(
May 30 '07 #7
NeoPa
32,556 Expert Mod 16PB
Check the Application Automation link now to see your contributions as part of a bona fide article.
May 30 '07 #8
I'm glad I could contribute to the article^.^

And I understand where you are coming from. I just wanted to clarify that I would never expect such from someone. Thank you for the offer to help in Excel. I might take you up on that offer^.^ I'm currently having to start from scratch on the database part though, so it might be a while.
May 31 '07 #9
NeoPa
32,556 Expert Mod 16PB
Remember if you have Excel problems to post the question in here (or PM me with a link to any new question - but remind me I asked you to, otherwise I may respond with my standard response which is not toooo friendly ;) I get so many PM requests you understand).
Good luck with your project anyway.
Jun 1 '07 #10
LacrosseB0ss
113 100+
faux, I also thank you for your code. Well done! Sadly a lot of posts on here are "Do my homework assignment" but yours was a serious coder looking for something they're stuck on.

Thanks again for the tips.
- LB
Jun 1 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: PerryC | last post by:
Is there a way to export an MS Access Report to Word/Excel that looks EXACTLY like it appears in Access? When I export to Excel, only certain data appears, titles, headings... all missing. The...
5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
8
by: Jerome Ranch | last post by:
Okay So I've got pivot tables setup in Access 2003. Only about 30K records in the current 2005 databases...the pivots summarize the info in a number of nice ways. I need to get the pivot tables...
21
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
7
by: Vanessa | last post by:
hi Everyone, I have two questions on exporting data to Excel using ASP (w/o converting formatted excel file into web page and then plug in the dynamic data): 1. Can we export data into...
0
by: Pradnya Patil | last post by:
Hi , I need to export some of the reports to MS EXCEL & MS WORD in a WEB APPLICATION.I also need to LOCK some of the Columns in EXCEL-sheet.Right now I need to run the Interoperability...
9
by: M K | last post by:
I would like to write code to export to excel, outlook and word. Any idea where a good resource to look? I know about using the VBA macros as I have done that in lotus notes ( but that is VB to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.