Create MS Word, Edit and Print a blank page

Share this post
FaceBook  Twitter  Mixx.mn     

To Edit and print a MS Word Document Use following code:-

1) Create a MS Word application

2) Add a new document

3) Display document by setting Visible property as True.

4) Confirm if document is visible otherwise wait.

5) Set a Font in document

6) Set Size of Font

7) Type you text.

8) Print the document

9) Quit word document.

 

Function EditandPrint_MSWord()


'1) Create a MS Word application
Set objWord = CreateObject("Word.Application")

'2) Add a new document
objWord.Documents.Add

'3) Display document by setting Visible property as True.
objWord.Visible = True

'4) Confirm if document is visible otherwise wait.
Call VerifyApplicationlaunch("Microsoft Word")
Set objSelection = objWord.Selection 

'5) Set a Font in document
objSelection.Font.Name = "Arial"

6) Set Size of Font
objSelection.Font.Size = "14"

'7) Type you text.
objSelection.TypeText "SCAN"

'8) Print the document
objWord.PrintOut()

'9) Quit word document.
objWord.Quit (False)

End Function

 

To Verify an application is visible or not , use following code:-

1) Create a Windows object

2) Get all applications opened on desktop

3) Compare your application name & check if application opens

4) Return True if application found.

 


Function VerifyApplicationlaunch(applicationname)
    on error  resume next
VerifyApplicationlaunch=False
While  VerifyApplicationlaunch=False

'1) Create a Windows object
    Set oDesc = Description.Create
        oDesc( "micclass" ).Value = "Window"

'2) Get all applications opened on desktop
        If Desktop.ChildObjects(oDesc).Count > 0 Then
                Set x = Desktop.ChildObjects(oDesc)
            For y = 0 to Desktop.ChildObjects(oDesc).Count - 2

'3) Compare your application name & check if application opens
                    windowname=x(y).GetROProperty("text")
            If   Right(windowname,Len(applicationname))= Trim(applicationname) Then

'4) Return True if application found.
                    VerifyApplicationlaunch=True
                    Exit for
            End If
            Next
    End if
Wend
End Function