David R
I know a few things...
- Local time
- Today, 04:15
- Joined
- Oct 23, 2001
- Messages
- 2,633
I'm finding it hard to believe that this is as hard as it appears to be. I'm going to blame deafness from the fireworks over the last weekend... 
Anyway, what I want to do is open a Word Template from a button in my database's main form, then immediately prompt the user for a filename and location via Save As. I don't want to use late bindings, as everyone in our office has Office 2003. However I have nothing in Tools>References for "Microsoft Word 2003", and adding the reference for "Microsoft Office 11.0 Object Library" failed to dispel the error message saying that all of the Word-specific variables and commands were undefined.
Bits in red are what are throwing "user-defined type not defined" errors.
If I use late bindings and strip out all the misunderstood variables: I can get the debugger to stop choking:
It doesn't throw an error message, but if I hover over it during a pause in execution it gives me <Method 'FileDialog' of object '_Application' failed>. Not very enlightening.
Please don't suggest "Super Easy Word", as it's impenetrable and overkill for what I want. I don't need to merge any documents, I'm literally doing this as a convenience to users so they don't have to worry about finding the template on the server (and so they don't overwrite my template every month).

Anyway, what I want to do is open a Word Template from a button in my database's main form, then immediately prompt the user for a filename and location via Save As. I don't want to use late bindings, as everyone in our office has Office 2003. However I have nothing in Tools>References for "Microsoft Word 2003", and adding the reference for "Microsoft Office 11.0 Object Library" failed to dispel the error message saying that all of the Word-specific variables and commands were undefined.
Code:
Private Sub buttonMonthlyReport_Click()
' Create a Word document from template.
Dim WordApp As [COLOR="Red"]Word.Application[/COLOR]
Dim strTemplateLocation As String
' Specify location of template
strTemplateLocation = "\\ng-ncsdmaster\NAC\Center for Community Solutions\Office Procedures\Forms-Spreadsheets\Monthly Report (Fill-in-Form).dot"
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo ErrHandler
WordApp.Visible = True
WordApp.WindowState = [COLOR="Red"]wdWindowStateMinimize [/COLOR]'value: 1
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
DoEvents
WordApp.Activate
With [COLOR="Red"]Dialogs[/COLOR]([COLOR="Red"]wdDialogFileSaveAs[/COLOR]) 'value: 80
.Name = "C:\My Documents\MonthlyReport" & fOSUserName() & Month(Today()) & Day(Today()) & ".doc"
.Show
End With
Set WordApp = Nothing
ErrHandler:
Set WordApp = Nothing
End Sub
If I use late bindings and strip out all the misunderstood variables: I can get the debugger to stop choking:
Code:
WordApp.Visible = True
WordApp.WindowState = 1
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
DoEvents
WordApp.Activate
With FileDialog(80) 'value: 80
.InitialFileName = "C:\My Documents\MonthlyReport" & fOSUserName() & Month(Now()) & Day(Now()) & ".doc"
.Show
End With
Please don't suggest "Super Easy Word", as it's impenetrable and overkill for what I want. I don't need to merge any documents, I'm literally doing this as a convenience to users so they don't have to worry about finding the template on the server (and so they don't overwrite my template every month).
Last edited: