Hi, as no-one has responded I will give you the following - it is entirely "as is" and I will struggle to respond with much help (I will try when I can). However, most of what you are after is in the MakeLetter() function - i.e. you will need to declare and manipulate a Word.Document type object. Once you have that you can actually perform most of the menu types calls in Word, after creating a Word.Document type object and see what methods and functions you have available. if you have difficulty please ask, but it may take a while. the other functions are primarily to support MakeLetter() and you may not need them. you may also have to add a "Microsoft Word xx.0 Object Library" reference under Tools then References in Microsoft Visual Basic (via Alt F11). the code below leaves Word maximised and ready for the user to edit the document, your template name should be in "strFileName" and your output filename should be stored in "strLetterName". i would recommend putting the whole lot in a separate module:
Public objWord As Word.Application
Public WordDoc As Word.Application
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassname As Any, ByVal lpWindowname As Any) As Long
Type adh_accOfficeGetFileNameInfo
hwndOwner As Long
strAppName As String * 255
strDlgTitle As String * 255
strOpenTitle As String * 255
strFile As String * 4096
strInitialDir As String * 255
strFilter As String * 255
lngFilterIndex As Long
lngView As Long
lngFlags As Long
End Type
' GetFileNameInfo flags
Public Const adhcGfniConfirmReplace = &H1 ' Prompt if overwriting a file?
Public Const adhcGfniNoChangeDir = &H2 ' Disable the read-only option
Public Const adhcGfniAllowReadOnly = &H4 ' Don't change to the directory the user selected?
Public Const adhcGfniAllowMultiSelect = &H8 ' Allow multiple-selection?
Public Const adhcGfniDirectoryOnly = &H20 ' Open as directory picker?
Public Const adhcGfniInitializeView = &H40 ' Initialize the view to the lView member or use last selected view?
Public Const adhcAccErrSuccess = 0
Declare Function adh_accOfficeGetFileName Lib "msaccess.exe" _
Alias "#56" (gfni As adh_accOfficeGetFileNameInfo, ByVal fOpen As Integer) As Long
Public Function MakeLetter(strLetterName As String, Optional strTemplateName As String, Optional strQueryName As String, Optional strDocumentName As String, Optional strParatext As String) As Boolean
On Error GoTo Err_MakeLetter
Dim rst As Recordset
Dim dbs As Database
Dim tdf As TableDef
Dim fld As Field
Dim varContents As Variant
Dim sngTemp As Single
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Dim ok As Boolean
Dim strFileName As String
Dim strSQL As String
Dim strMess As String
If Len(Trim(strTemplateName)) < 3 Then
strFileName = getFileName("Select Standard Template Required", strTemplatesPath & "Templates", "TEMPLATE FILES(*.doc; *.dot)")
Else
strFileName = strTemplateName
End If
If Len(Trim(strFileName)) > 0 Then
If FindWindow("OpusApp", vbNullString) = 0 Then
Set objWord = CreateObject("Word.Application.8")
Else
Set objWord = GetObject(, "Word.Application.8")
End If
objWord.Visible = True
objWord.WindowState = wdWindowStateMaximize
Set objWordDoc = objWord.Documents.Add(strFileName)
If Len(Trim(strDocumentName)) > 3 Then
objWordDoc.Bookmarks("DocumentName").Select
objWordDoc.Application.Selection.TypeText Text:=strDocumentName
If objWordDoc.ActiveWindow.View.SplitSpecial = wdPaneNone Then
objWordDoc.ActiveWindow.ActivePane.View.Type = wdPrintView
Else
objWordDoc.ActiveWindow.View.Type = wdPrintView
End If
objWordDoc.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If objWordDoc.ActiveWindow.View.SplitSpecial = wdPaneNone Then
objWordDoc.ActiveWindow.ActivePane.View.Type = wdPrintView
Else
objWordDoc.ActiveWindow.View.Type = wdPrintView
End If
End If
objWordDoc.SaveAs FileName:=strLetterName
objWord.WindowState = wdWindowStateMaximize
Set objWord = Nothing
MakeLetter = True
Else
strMess = "No selection made!"
MsgBox strMess, vbOKOnly + vbExclamation, "Oops"
End If
Exit_MakeLetter:
DoCmd.SetWarnings True
Exit Function
Err_MakeLetter:
MsgBox Err.Description
Resume Exit_MakeLetter
End Function
Function getFileName(strWindowTitle As String, strInitialDir As String, strFileTypes As String)
Dim gfni As adh_accOfficeGetFileNameInfo
Dim lngFlags As Long
Dim strFileName As String
' On Error GoTo HandleErrors
lngFlags = lngFlags Or adhcGfniConfirmReplace Or adhcGfniNoChangeDir Or adhcGfniInitializeView
With gfni
.lngView = 1
.lngFlags = lngFlags
.strFilter = strFileTypes
.lngFilterIndex = 1
.strFile = ""
.strDlgTitle = strWindowTitle
.strOpenTitle = "Select"
.strFile = ""
.strInitialDir = strInitialDir
End With
If adhOfficeGetFileName(gfni, -1) = adhcAccErrSuccess Then
strFileName = Trim(gfni.strFile)
If strFileName <> "" Then
getFileName = strFileName
Else
MsgBox "You have not chosen a file", vbOKOnly
End If
End If
End Function
Function adhOfficeGetFileName(gfni As adh_accOfficeGetFileNameInfo, _
ByVal fOpen As Integer) As Long
Dim lng As Long
With gfni
.strAppName = RTrim$(.strAppName) & vbNullChar
.strDlgTitle = RTrim$(.strDlgTitle) & vbNullChar
.strOpenTitle = RTrim$(.strOpenTitle) & vbNullChar
.strFile = RTrim$(.strFile) & vbNullChar
.strInitialDir = RTrim$(.strInitialDir) & vbNullChar
.strFilter = RTrim$(.strFilter) & vbNullChar
SysCmd acSysCmdClearHelpTopic
lng = adh_accOfficeGetFileName(gfni, fOpen)
.strAppName = RTrim$(adhTrimNull(.strAppName))
.strDlgTitle = RTrim$(adhTrimNull(.strDlgTitle))
.strOpenTitle = RTrim$(adhTrimNull(.strOpenTitle))
.strFile = RTrim$(adhTrimNull(.strFile))
.strInitialDir = RTrim$(adhTrimNull(.strInitialDir))
.strFilter = RTrim$(adhTrimNull(.strFilter))
End With
adhOfficeGetFileName = lng
End Function