Re: Word Template Automation

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Eric Lawrence [MSFT] (e_lawrence_at_hotmail.com)
Date: 02/22/04

  • Next message: anonymous_at_discussions.microsoft.com: "Re: Word Template Automation"
    Date: Sat, 21 Feb 2004 17:46:42 -0800
    
    

    Is there some reason your template filename doesn't have a file extension?

    -- 
    Thanks,
    Eric Lawrence
    Program Manager
    Assistance and Worldwide Services
    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Frank Brady" <anonymous@discussions.microsoft.com> wrote in message
    news:1436b01c3f8c7$17576650$a001280a@phx.gbl...
    > The following code opens a word template as a new document
    > and appends text to the new document. This works in
    > Windows 98, however when ported to Windows XP I get ERROR
    > 5152 - this is not a valid file name. The file is there
    > and it is not corrrupt.
    >
    > The error occurs in the following line:
    >
    > Set doc1 = wrd.Documents.Add
    > (Template:="c:\Access\Data\RefLetterTemp",
    > NewTemplate:=False)
    >
    >
    >
    > Private Sub cmdReferralLetter_Click()
    >     Dim db As Database
    >     Dim rs As Recordset
    >     Dim strSql As String
    >     Dim strMD
    >
    >  On Error GoTo err_handler
    >
    >     strSql = "SELECT  * FROM tblPhysican where
    > tblPhysican.ID = """ & strMD & """;"
    >   Set db = CurrentDb
    >   Set rs = db.OpenRecordset(strSql)
    >
    >   Dim wrd As Word.Application
    >   Dim doc1 As Word.Document
    >   Dim rng As Word.Range
    >   Dim SerNo As String
    >   SerNo = CStr(CDec(Time()))
    >   SerNo = Mid(SerNo, InStr(SerNo, ".") + 1)
    >
    >   Set wrd = New Word.Application
    >
    > 'set pointer to new doc based on Referral templet
    >   Set doc1 = wrd.Documents.Add
    > (Template:="c:\Access\Data\RefLetterTemp",
    > NewTemplate:=False)
    >
    > With wrd.ActiveDocument
    >     Set rng = .Bookmarks("DrName").Range
    >       rng.InsertBefore Nz(rs!FNAME & " " & rs!LNAME & "
    > M.D.")
    >     Set rng = .Bookmarks("DrStreet").Range
    >       rng.InsertBefore Nz(rs!ADDR1)
    >
    >     If rs!ADDR2 <> "" Then
    >         Set rng = .Bookmarks("DrAddLn2").Range
    >         rng.InsertBefore vbCrLf & Nz(rs!ADDR2)
    >     End If
    >
    >     Set rng = .Bookmarks("DrCSZ").Range
    >       rng.InsertBefore Nz(rs!City) & ", " & Nz(rs!State)
    > & "   " & Nz(rs!Zip) & vbCrLf & vbCrLf
    >     Set rng = .Bookmarks("DrLname").Range
    >       rng.InsertBefore Nz(rs!LNAME)
    >     Set rng = .Bookmarks("Re").Range
    >       rng.InsertBefore Forms![frmpatients]![LNAME] & ", "
    > & Forms![frmpatients]![FNAME]
    >     Set rng = .Bookmarks("PtFname").Range
    >       rng.InsertBefore Forms![frmpatients]![FNAME]
    >     Set rng = .Bookmarks("HeShe").Range
    >       rng.InsertBefore IIf(Forms![frmpatients]![SEX]
    > = "M", "He", "She")
    >     Set rng = .Bookmarks("DOS").Range
    >       rng.InsertBefore Format(Me![DateSeen], "dddd, mmm d
    > yyyy")
    >       ' Returns "Wednesday, Jan 27 1993".
    >     Set rng = .Bookmarks("Note").Range
    >       rng.InsertBefore Nz(Me![Note])
    >
    >     .SaveAs "C:\My Documents\" & rs!LNAME & SerNo
    > End With
    >
    > wrd.Visible = True
    >
    >
    > exit_Hear:
    >  Set rng = Nothing
    >  Set doc1 = Nothing
    >  Set wrd = Nothing
    > Exit Sub
    >
    > err_handler:
    > Select Case Err.Number
    >     Case Else
    >         MsgBox Err.Number & "   " & Err.Description,
    > vbExclamation, "Error Referal Letter to MS Word"
    > End Select
    > Resume exit_Hear
    >
    > End Sub
    

  • Next message: anonymous_at_discussions.microsoft.com: "Re: Word Template Automation"

    Relevant Pages

    • Re: Memory problem (I think ???)
      ... Q1 Perhaps Union gets bogged down by the total number of added ... Dim rng As Range, rng2 As Range, ar As Range ... Dim ScrArea As String ... Set rng = FormatRegion(SearchCell, ...
      (microsoft.public.excel.programming)
    • Re: Update a range within a macro using an input box or similar
      ... Dim RandomNumberArray As Variant ... ' Create a new recordset object ... 'to read array is RandomNumberArray, RandomNumberArrayetc. ... Set rng = Application.Union)) ...
      (microsoft.public.excel.programming)
    • RE: "Folder does not contain contacts" in Microsoft Outlook
      ... i keep getting the message "Folder does not ... Dim appExcel As Excel.Application ... Dim strSheet As String ... Set rng = wks.Cells ...
      (microsoft.public.outlook.program_vba)
    • Re: Formula to consolidate numbers?
      ... this particular macro took a very long time to run. ... Dim rng_forward As Range ... Dim StartCell As String ... Set rng = Find_Range(returnConnection(strValue, ...
      (microsoft.public.excel.misc)
    • Re: still & issue but tried something
      ... Sub Delete_empty_rows_fix ... Dim rng1 As Range ... Set rng = Range) ...
      (microsoft.public.excel.programming)