Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.



Create Excel File or Word Document from Microsoft Access and write information into them. Every application that supports Automation provides at least one type of object. For example, a word processing application may provide an Application object, a Document object and a Toolbar object. To create an ActiveX object, assign the object returned by CreateObject to an object variable.

Create an MS-Word File

The first example creates a Word File and writes some text into it and saves with a name.

Public Sub CreateWordDoc() 
Dim WordObj As Object
On Error goto CreateWordDoc_Err

Set WordObj = CreateObject("word.application")
With WordObj
   .Application.Visible = True
   .Application.Documents.Add "Normal", , 0, True
   .ActiveDocument.Content = "THIS IS MY TEST DOCUMENT."
   .Application.ActiveDocument.SaveAs "C:\myDocument2.doc"
End With
Set WordObj = Nothing

Exit Sub

msgbox Err.Description,,"CreateWordDoc"
Resume CreateWordDoc_Exit
End Sub 

Creating an MS-Excel File

The Next example creates an Excel Worksheet and writes a line of text in Column A, Row 1 and saves it with a Name. This code starts the application creating the object, in this case, a Microsoft Excel spreadsheet. Once an object is created, you reference it in code using the object variable you defined. You access properties and methods of the new object using the object variable, ExcelSheet and other Microsoft Excel objects, including the Application object and the Cells collection.

Public Sub CreateExcelSheet()
Dim ExcelSheet As Object

On Error goto CreateExcelSheet_Err

Set ExcelSheet = CreateObject("Excel.Sheet")

With ExcelSheet
   .Application.Visible = True
   .Application.Cells(1, 1).Value = "This is Column A, row 1"
   .SaveAs "C:\TEST.XLS"
End With

Set ExcelSheet = Nothing

Exit Sub
Msgbox Err.Description,,"CreateExcelSheet"
Resume CreateExcelSheet_Exit
End Sub 

Next >> Create Text File from Access.


1 comment:

  1. There is good tool which works with excel files and possible more than-fix Excel tools,it has free status as far as I can see,also software works on a very important report, with statistical data, graphics, tables and a lot of critical information and it is lost at once,will analyze your damaged document and show you its content in a preview window,allow you to fix files Excel and see, which elements will be recovered and which are damaged too badly,can choose, whether you'd like to recover all of your damaged documents manually and spend many days for this purpose.


Comments subject to moderation before publishing.


Subscribe in a reader
Your email address:

Delivered by FeedBurner


Popular Posts

Blog Archive

Powered by Blogger.

Follow by Email


Forms Functions How Tos MS-Access Security Reports Class Module msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Array External Links Queries msaccess reports Downloads msaccess tips Accesstips Objects Collection Object Property Event Menus and Toolbars Controls MsaccessLinks Process Controls WithEvents Art Work VBA msaccess How Tos Combo Boxes Dictionary Object Graph Charts List Boxes Query msaccessQuery Calculation Command Buttons Form Report Command Button Data Emails and Alerts RaiseEvent Custom Functions Custom Wizards DOS Commands Data Type Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Item Key msaccessprocess security advanced Access Security Add Auto-Number Field Type Fields Form Instances Macros Menus Recordset SubForm Top Values Variables msaccess email msaccess menus progressmeter Access2007 Copy Excel Expression Join Methods Microsoft Numbering System Records Security Split Table Time Difference Utility Workgroup Wrapper Classes database function ms-access msaccess wizards reference text tutorial vba code Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Data Filtering Database Records Defining Pages Diagram Disk Dynamic Lookup Error Handler Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Tables Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif msaccess msaccess alerts pdf files restore switch toolbar updating upload