Microsoft word Project

Joined
Jan 4, 2011
Messages
8
Programming Experience
Beginner
Hi im new to programming and working to my final year project, i need to produce a GUI which can open a flashdrive, read a .doc file and preview it in a form, and after that will print it, is it possible with vb.net 2008? and how?the normal openfiledialog control won't do it, it only works for .text file, any response will be highly appreciated, thanks in advance
 
I use 2005 so it will be slightly different in your program.

To access Microsoft Word:
1) Set a COM reference in your project's reference tab
2) At the top of your code, include an import to "Microsoft.Office.Interop.Word"

That will allow you to access the Word objects.
 
tnx ggunter, but i tried that method many times, but it keeps posting an error saying some of my variable are not defined, and i can't figure out whats wrong, any sample code pls to where i can get started?
 
Here's a quickie form with just four buttons. It's not perfect but it will suffice to give you the general idea.

VB.NET:
Option Strict On

Imports Microsoft.Office.Interop.Word

Public Class Form1

    Private wrdApp As Microsoft.Office.Interop.Word.Application
    Private wrdDoc As Microsoft.Office.Interop.Word.Document

    Private Sub closeButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles closeButton.Click

        Try
            wrdDoc.Close()
            wrdApp.Quit()

            wrdDoc = Nothing
            wrdApp = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click

        Me.Close()

    End Sub

    Private Sub openBlankButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles openBlankButton.Click

        Try
            wrdApp = New Microsoft.Office.Interop.Word.Application

            wrdDoc = wrdApp.Documents.Add()

            ''These are optional
            With wrdApp
                .Visible = True
                .DisplayAlerts = WdAlertLevel.wdAlertsNone
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub openExistingButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles openExistingButton.Click
        Dim documentPath As Object = "Path To Existing Word Document"

        Try
            wrdApp = New Microsoft.Office.Interop.Word.Application

            wrdDoc = wrdApp.Documents.Open(documentPath)

            'These are optional
            With wrdApp
                .Visible = True
                .DisplayAlerts = WdAlertLevel.wdAlertsNone
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub
End Class

Microsoft allows you to access their products and manipulate them directly from your code. There are also Interops for Excel and Powerpoint.
 
Back
Top