VB icon

Auto-Typing in MS Word with .NET!

Email
Submitted on: 1/1/2015 8:36:00 PM
By: Javier García Alonso (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: VB.NET
Views: 1379
 
     This code opens MS Word, creates a new document, and starts writing a text in it letter by letter.Just create a new proyect, a normal windows aplication, add a reference to Microsoft Word Object Library, and copy/paste this code. Then set form opacity to 0%. Easy to implement and Cool effect, isn't?
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Auto-Typing in MS Word with .NET!
// Description:This code opens MS Word, creates a new document, and starts writing a text in it letter by letter.Just create a new proyect, a normal windows aplication, add a reference to Microsoft Word Object Library, and copy/paste this code. Then set form opacity to 0%. Easy to implement and Cool effect, isn't?
// By: Javier García Alonso (from psc cd)
//
// Assumes:Don´t forget to add a reference to Microsoft Word 9.0 Object Library! or 10.0 if you are Office XP user!
//**************************************

'Message that will appear in MS Word
 Private Shared message As String = "Hey, How are you doing?"
 'Variable to iterate
 Private Shared i As Integer
 'Timer Object
 Private Shared WithEvents temp As New Timer()
 'Word Objects: application object and document object
 Private Shared aplicationword As New Word.Application()
 Private Shared documentword As New Word.Document()
 'Boolean variable to escape of while loop
 Private Shared exiting As Boolean = True
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Word is visible and activate
aplicationword.Visible = True
aplicationword.Activate()
'One document added to Word
documentword = aplicationword.Documents.Add
'Added an event handler
AddHandler temp.Tick, AddressOf TimerEventProcessor
'Setting timer properties (delay)
temp.Interval = 350
'Yeah!, let's go
temp.Start()
i = 0
While exiting = False
 Application.DoEvents()
End While
 End Sub
 Private Shared Sub TimerEventProcessor(ByVal sender As Object, ByVal e As System.EventArgs)
'If I've finished writting
If i = message.Length Then
 temp.Stop()
 exiting = True
 Exit Sub
End If
'else writes a new letter
aplicationword.Selection.TypeText(message.Chars(i))
i += 1
 End Sub


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.