Ms-Access Advanced VBA Programming Techniques, Tips and Tricks.

Ads

CREATE EXCEL WORD FILE FROM ACCESS

CREATE EXCEL OR WORD FILE FROM ACCESS

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. 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")
WordObj.Application.Visible = True
WordObj.Application.Documents.Add "Normal", , 0, True
WordObj.ActiveDocument.Content = "THIS IS MY TEST DOCUMENT."
WordObj.Application.ActiveDocument.SaveAs "C:\myDocument2.doc"
WordObj.Application.Quit
Set WordObj = Nothing
CreateWordDoc_Exit:
Exit Sub

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

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")
ExcelSheet.Application.Visible = True
ExcelSheet.Application.Cells(1, 1).Value = "This is Column A, row 1"
ExcelSheet.SaveAs "C:\TEST.XLS"
ExcelSheet.Application.Quit
Set ExcelSheet = Nothing
CreateExcelSheet_Exit:
Exit Sub
CreateExcelSheet_Err:
Msgbox Err.Description,,"CreateExcelSheet"
Resume CreateExcelSheet_Exit
End Sub 

Next >> Create Text File from Access.

Share:

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.

    ReplyDelete

Trending

Infolinks Text Ads

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Labels

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

Featured Post

Activity Dates and Quarterly Reports

There are four Quarters in a Year: Jan - Mar = 1st Quarter Apr - Jun = 2nd Jul - Sep = 3rd Oct - Dec = 4th First three months of the yea...

Labels

Blog Archive

Recent Posts