Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

VB Code to use open office writer when Ms word in not available

$
0
0
I am using the code below to open documents in Ms word. How can I amend this to switch to Open Office writer when the Ms office suite is not installed? Alternatively I could live with just switching to Open office as an alternative version.

Imports System
Imports System.IO
Imports System.Collections
Imports System.Data.SqlClient
Imports Word = Microsoft.Office.Interop.Word
Imports System.Threading
Imports System.Runtime.InteropServices



 Private Sub btnSingleWriter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSingleWriter.Click

        Dim oWord As Word.Application
        Dim oDoc As Word.Document

        'Start Word and open the document template.

        oWord = CreateObject("Word.Application")
        oWord.Visible = False
        oDoc = oWord.Documents.Add(Application.StartupPath & "\Letters\" & mSingleSenderTemplate)

        oDoc.Bookmarks.Item("SendersAddress").Range.Text = gSenderOneAddress1 & " " & vbCrLf & gSenderOneTown & " " & vbCrLf & gSenderOnePostcode.ToUpper & " " & vbCrLf & gSenderOneCountry
        oDoc.Bookmarks.Item("Recipient").Range.Text = txtSalutationFrench.Text & " " & gRecipientForenames & " " & gRecipientLastName
        oDoc.Bookmarks.Item("RecipientAddress").Range.Text = gRecipientAddress1 & " " & vbCrLf & gRecipientPostcode & "   " & gRecipientTown & " " & vbCrLf & gRecipientCountry
        oDoc.Bookmarks.Item("OpeningEnglish").Range.Text = gLetterOpening
        oDoc.Bookmarks.Item("DateEnglish").Range.Text = gDay & " " & gMonth & " " & gYear
        oDoc.Bookmarks.Item("FirstSender").Range.Text = gSenderOneForenames & " " & gSenderOneLastName
        oDoc.Bookmarks.Item("iFirstSender").Range.Text = gSenderOneForenames & " " & gSenderOneLastName
        oDoc.Bookmarks.Item("iSendersAddress").Range.Text = gSenderOneAddress1 & " " & vbCrLf & gSenderOneTown & " " & vbCrLf & gSenderOnePostcode.ToUpper & " " & vbCrLf & gSenderOneCountry
        oDoc.Bookmarks.Item("SentFrom").Range.Text = TxtLetterSentFrom.Text & " " & gDay.Trim & " " & gMonthFrench.Trim & " " & gYear.Trim
        oDoc.Bookmarks.Item("iRecipient").Range.Text = gRecipientTitle & " " & gRecipientForenames & " " & gRecipientLastName
        oDoc.Bookmarks.Item("iRecipientAddress").Range.Text = gRecipientAddress1 & " " & vbCrLf & gRecipientPostcode & "   " & gRecipientTown & " " & vbCrLf & gRecipientCountry
        oDoc.Bookmarks.Item("OpeningFrench").Range.Text = txtSalutationFrench.Text
        oDoc.Bookmarks.Item("iOpeningFrench").Range.Text = txtSalutationFrench.Text
        oDoc.Bookmarks.Item("jFirstSender").Range.Text = gSenderOneForenames & " " & gSenderOneLastName
        oDoc.Bookmarks.Item("FR1Title").Range.Text = gFR1Title

        oWord.Visible = True
        oWord = Nothing
        releaseObject(oDoc)
        releaseObject(oWord)


    End Sub






I have tried searching but cannot find anything I understand....

Any assistance would be greatfully appreciated.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>