Instructions
Things You'll Need:
- Visual Basic
- Microsoft Word
- Step 1
Open the Visual Basic application and create a new project using the "Ctrl" and "N" keys. Select the template labeled "Windows Forms Application."
- Step 2
Select "Project" from the menu bar, then select the "References" option. Check the item "Microsoft Word object library" and then click the "OK" button to continue.
- Step 3
Create a button labeled "ButtonOne" on the form.
- Step 4
Double click on "ButtonOne" to open the code window. Insert the following code below the line "Private Sub ButtonOne_Click":
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRng As Word.Range
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.InsertAfter("This is the new document you created.")
Me.Close() - Step 5
Insert the following code at the top of the code for "Form1":
Imports Word = Microsoft.Office.Interop.Word - Step 6
Execute the code in debug mode using the "F5" key.
- Step 7
Click on the button labeled "ButtonOne" to execute the code. A Microsoft Word document will be displayed in a new window with the text "This is the new document you created."
No comments:
Post a Comment