Re: Opening a MS Word document through a button click

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm still not quite understanding what to do.

The first reply indicated that I needed to enclose readOnly in brackets to
be able to use it.

The second reply indicated that I don't need to handle "missing" parameters.

Where would the line of code: m_Document =
m_Word.Documents.Add(Template:=CType(m_TemplatePath, Object)) be placed?

What I am trying to accomplish is clicking a button to open the program
documentation which is in the MS Word format. The program documentation will
explain how the program works and how it has met the requirements of the
user who requested the application. Additionally, it will list system
requirements. The goal is that this documentation should not be able to be
changed by the user.

"Fred Hedges" <dontlike@xxxxxxxxxxxx> wrote in message
news:e4kam0$3da$1$8302bc10@xxxxxxxxxxxxxxxxxxx

Would like to point out that you don't need to handle "missing"
parameters.
For example:

m_Document = m_Word.Documents.Add(Template:=CType(m_TemplatePath,
Object))

Here using "Parameter := Variable", so state which variable should be
passed
into which parameter, all others automatically being "missing" by default.

Secondly, the word enumerations won't automatically be in your namespace,
so
.NET won't be able to find them. I use the fully qualified name in order
to
access them. For example, the wdCollapseEnd value is found in the Word.
namespace:

theRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)


Hope this helps.


"Charlie Brookhart" <charliebrookhart46@xxxxxxxxxxx> escribió en el
mensaje
news:JtudnWUo5by1wPDZRVn-pw@xxxxxxxxxxxxxxx
I am trying to write a code for a button click event. When the button is
clicked, it is supposed to bring up an open file dialog box to allow the
user to select the document they which to open. That word doucment will
then
be opened and displayed in MS Word. The code I have below doesn't quite
work
the way I expected it to.

First, VB is complaining that the variable readOnly is not declared. How
can
that be when it is declared as Dim readOnly as Object = False? The next
thing VB is complaining about is that As is not valid as a keyword
identifier. If I comment out the read only line, it seems to work.

The next thing that doesn't quite work as expected is the open file
dialog
box displays no file types. How would those be added?

Private Sub button1_Click(sender As Object, e As System.EventArgs)
' Use the open file dialog to choose a word document
If Me.openFileDialog1.ShowDialog() = DialogResult.OK Then
' set the file name from the open file dialog
Dim fileName As Object = openFileDialog1.FileName
Dim readOnly As Object = False
Dim isVisible As Object = True
' Here is the way to handle parameters you don't care about in .NET
Dim missing As Object = System.Reflection.Missing.Value
' Make word visible, so you can see what's happening
WordApp.Visible = True
' Open the document that was chosen by the dialog
Dim aDoc As Word.Document = WordApp.Documents.Open(fileName, missing,
[readOnly], missing, missing, missing, missing, missing, missing,
missing,
missing, isVisible) ' Activate the document so it shows up in front
aDoc.Activate();
' Add the copyright text and a line break
WordApp.Selection.TypeText("Copyright C# Corner")
WordApp.Selection.TypeParagraph()
End If
End Sub 'button1_Click






.



Relevant Pages

  • Re: Opening a MS Word document through a button click
    ... Dim aDoc As Word.Document = WordApp.Documents.Open(fileName, ... The second reply indicated that I don't need to handle "missing" parameters. ... documentation which is in the MS Word format. ... The next thing that doesn't quite work as expected is the open file ...
    (microsoft.public.dotnet.languages.vb)
  • Opening a MS Word document through a button click
    ... that be when it is declared as Dim readOnly as Object = False? ... The next thing that doesn't quite work as expected is the open file dialog ... Private Sub button1_Click ... Dim aDoc As Word.Document = WordApp.Documents.Open(fileName, missing, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Opening a MS Word document through a button click
    ... Would like to point out that you don't need to handle "missing" parameters. ... that be when it is declared as Dim readOnly as Object = False? ... The next thing that doesn't quite work as expected is the open file dialog ... Private Sub button1_Click ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Extracting data/numerical values from a give list
    ... in all the missing data between 10211 and 10219. ... Dim i As Long, j As Long ... Const LowerLimit As Long = 1 ... Const UpperLimit As Long = 99999 ...
    (microsoft.public.excel.programming)
  • Re: Error Report
    ... I do have a primary key. ... you could use a vba routine to return the null fields. ... Dim rs As DAO.Recordset ... missing information, only specifying the fields that are missing ...
    (microsoft.public.access.reports)