Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making MSWord2007 invisible?

Status
Not open for further replies.

Ajb2528

Technical User
Feb 22, 2002
270
GB
Hi!

I have written some VB.Net (2008) to run a mailmerge... my problem being is that I want to make the instance of Word invisible to the user. The nearest that I van get is to minimise the Word application. The code that I have written is below.

Public Sub fred()

Dim sqlQry As String = "SELECT TOP 2 ContactName, ContactName AS ContactName1 from customers"
'Get the values from table
Dim ObjDatatable As DataTable = RetrieveData.GetData(sqlQry, DataBaseQueryType.Datatable)
Dim strTemplateFileName As String = "Love2shopReferrals.doc"
'Word merging
Dim objApp As Word.Application

objApp = CreateObject("Word.Application")
objApp.Visible = False

If IsNothing(objApp) = False Then
Dim strDocFileName As String
For Each row As DataRow In ObjDatatable.Rows
'Open the Document
objApp.Documents.Open(Path.Combine(ApplicationPath, strTemplateFileName))
objApp.WindowState = WdWindowState.wdWindowStateMinimize
objApp.Visible = False
strDocFileName = Convert.ToString(row(0)) & ".doc"
Dim intCount As Integer = 0
For Each MergeField As Word.MailMergeField In objApp.ActiveDocument.MailMerge.Fields
'Select the text
MergeField.Select()
'Type the text
objApp.Selection.TypeText(Convert.ToString(row(intCount)))
intCount += 1
Next
'Save the document
objApp.ActiveDocument.SaveAs(Path.Combine(ApplicationPath, strDocFileName))
'Close the document
objApp.Documents.Close()
Next
'Dont save the template changes
objApp.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)
'Dispose
End If
objApp = Nothing
ObjDatatable.Dispose()
ObjDatatable = Nothing

NAR(objApp)

End Sub

If anyone can help me on this it would be appreciated!

Regards,

Alan

P.S. sorry about the code formatting!
 
Not sure if this is what you want and probably a better way but here is the following.

[green]Normal.ThisDocument.Application.Visible = false[/green]

This is within a word module itself so may differ with your code.

Hope this helps........

Instead of shooting where I was, you should have shot where I was going to be. - Lrrr (Planet Nintendooo64)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top