Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
programming_microsoft_word_-_02_-_our_first_program [2013/12/24 21:26]
wekkel
programming_microsoft_word_-_02_-_our_first_program [2018/07/29 01:22] (current)
Line 58: Line 58:
 In your form, add a reference to the Interop language by means of the following code (place it above the text where the form starts with "​Public Class Form1",​ see sample below). In your form, add a reference to the Interop language by means of the following code (place it above the text where the form starts with "​Public Class Form1",​ see sample below).
  
-<html>Imports Microsoft.Office.Interop.Word</​html>+<pre> 
 +Imports Microsoft.Office.Interop.Word 
 +</pre>
  
 [[http://​www.visualstudio.com/​en-us/​downloads/​|{{http://​s22.postimg.org/​6t56w2d2p/​06_VS_Add_Ref3.png?​1024}}]] [[http://​www.visualstudio.com/​en-us/​downloads/​|{{http://​s22.postimg.org/​6t56w2d2p/​06_VS_Add_Ref3.png?​1024}}]]
Line 65: Line 67:
  
 == Designing the GUI of our program == == Designing the GUI of our program ==
 +
 Our program will be steered from the Graphical User Interface (GUI). This is a familiar Windows form on which we will place a textbox and a button. The textbox and button can be dragged with the mouse from the toolbox on the left onto Form1 (see picture below). Drag them around and resize them as fit. We will not change their names in this round. Our program will be steered from the Graphical User Interface (GUI). This is a familiar Windows form on which we will place a textbox and a button. The textbox and button can be dragged with the mouse from the toolbox on the left onto Form1 (see picture below). Drag them around and resize them as fit. We will not change their names in this round.
  
Line 74: Line 77:
  
 == Coding time == == Coding time ==
 +
 Now for some action. Double click the button you just dragged onto Form1. The IDE will show you the code behind that button and places the cursor ready to insert some code. Alternatively,​ you can switch to the code behind Form1 by right-clicking '​Form1'​ in the Solution Explorer (see picture), but then you will have to go to the block that holds the code for the button yourself. Now for some action. Double click the button you just dragged onto Form1. The IDE will show you the code behind that button and places the cursor ready to insert some code. Alternatively,​ you can switch to the code behind Form1 by right-clicking '​Form1'​ in the Solution Explorer (see picture), but then you will have to go to the block that holds the code for the button yourself.
  
Line 82: Line 86:
 You will be inserting the following code on that exact spot: You will be inserting the following code on that exact spot:
  
-<code>Dim wdApp As New Word.Application+<pre> 
 +Dim wdApp As New Word.Application
 Dim wdDoc As Word.Document Dim wdDoc As Word.Document
  
Line 94: Line 99:
 wdApp.ActiveWindow.Selection.TypeText(TextBox1.Text) wdApp.ActiveWindow.Selection.TypeText(TextBox1.Text)
  
-wdApp = Nothing</​code>+wdApp = Nothing 
 +</pre>
  
 When done, it will look like this: When done, it will look like this:
Line 117: Line 123:
  
 == How does this code work? == == How does this code work? ==
 +
 Below, we will go through the code in more detail but first the warning that his code is not suitable yet for our purposes. You will notice that - if you had Word already running - a second version of Word was started that will conflict with the earlier running version. If you close the newly created document and close the 2nd version of  Word running, it will complain about another version of Word running. Close Word but do not overwrite the normal.dot file. We will fix this behaviour in future contributions. ​ Below, we will go through the code in more detail but first the warning that his code is not suitable yet for our purposes. You will notice that - if you had Word already running - a second version of Word was started that will conflict with the earlier running version. If you close the newly created document and close the 2nd version of  Word running, it will complain about another version of Word running. Close Word but do not overwrite the normal.dot file. We will fix this behaviour in future contributions. ​
  
Line 132: Line 139:
  
 == Next contribution:​ step by step == == Next contribution:​ step by step ==
 +
 The next contribution deals with the GUI. We will create a little program that hides in the Windows tray and will show a menu when right-clicked with the mouse. This menu will hold all our future Word actions, so that we will have Word automation ready at our fingertips when needed. The next contribution deals with the GUI. We will create a little program that hides in the Windows tray and will show a menu when right-clicked with the mouse. This menu will hold all our future Word actions, so that we will have Word automation ready at our fingertips when needed.
  
 [[http://​www.devtome.com/​doku.php?​id=programming_microsoft_word_-_03_-_run_program_from_the_tray|Next contribution (part 3)]] [[http://​www.devtome.com/​doku.php?​id=programming_microsoft_word_-_03_-_run_program_from_the_tray|Next contribution (part 3)]]
  
-[[Category:​Programming]]+ 
 +[[Category:​Computing]] | [[Category:​Programming]] | [[Category:​Software]]

QR Code
QR Code programming_microsoft_word_-_02_-_our_first_program (generated for current page)