[AccessD] Programatically opening Word docs from Access

rosalyn.clarke at barclays.com rosalyn.clarke at barclays.com
Fri Jul 25 06:27:25 CDT 2008


Hi guys

I'm (still) working on code to find and replace obsolete fonts in Word
documents.

I had this working last week but oddly, this week it is falling over. What's
changed is I have a new laptop, but I can't see any differences.

The code errors at the line 

Set doc = WordBasic.FileOpen(Name:=sFullPath, Password:=strPassword)

...with a '448 named argument not found' error.

If you instantiate Word using Dim wrd as New Word.Application instead of the
CreateObject method, it instantiates Word and opens the document, but does
not associate the new document with the programmatically created Word
instance.

If you open the document using wrd.documents, it opens it read only and you
can't make any changes (this is a bug).

Apart from wondering if anyone has come across this behaviour before, I'm
wondering if it's worth me porting all my code into Word instead of running
it from Access. The full procedure is below.

TIA for any help...

Roz



Public Sub ProcessDoc2(sPath As String, sName As String, intID As Integer)
On Error GoTo errProcessDoc2
'auto-update document / template

Dim wrd As Object
Dim doc As Word.Document
Dim sFullPath As String
    Dim iFonts As Integer
    Dim sFontName As String
    Dim J As Integer
    Dim X As Long, Y As Long
    Dim bFoundFont As Boolean
    Dim sFontList(99) As String
    Dim strPassword As String
Dim cmd As New ADODB.Command
Dim strSQL As String
Dim sProtection As String
Dim sNewFont As String
    
'open the document with password info, whatevs

strPassword = "footba11"

sFullPath = sPath & sName
Debug.Print sFullPath
    
Set wrd = CreateObject("Word.Application")
Set doc = WordBasic.FileOpen(Name:=sFullPath, Password:=strPassword)

If doc.ProtectionType <> wdNoProtection Then
    sProtection = doc.ProtectionType
    doc.Unprotect Password:=strPassword
End If

wrd.Visible = True

    iFonts = 0
    X = doc.Characters.Count
    Y = 0
    
sNewFont = "Expert Sans Regular"

'start grabbing selections of contiguous fonts and updating
 Do Until Y >= X
    wrd.Selection.SelectCurrentFont
    sFontName = wrd.Selection.Font.Name

        For J = 1 To iFonts
           If sFontList(J) = sFontName Then bFoundFont = True
        Next J
        If Not bFoundFont Then
            iFonts = iFonts + 1
            sFontList(iFonts) = sFontName
        End If
        'update to new font if font is obsolete
        Select Case sFontName
        Case Is = "Barclays", "Barclays Serif", "Expert Serif Regular"
            UpdateProperty intID, "Font", sFontList(J), sNewFont, "Font
discontinued"
            wrd.Selection.Font.Name = sNewFont
        Case Else
            UpdateProperty intID, "Font", sFontList(J), "n/a", "No change -
check only"
        End Select
    Y = wrd.Selection.End
    wrd.Selection.Start = Y + 1
Loop

        
'reapply protection
If IsNull(sProtection) = False Then
    doc.Protect sProtection, Password:=strPassword
End If
    
exitProcessDoc2:
    doc.Close True 'save document on Close
    wrd.Quit
    Exit Sub

errProcessDoc2:
    MsgBox Err.Number & " " & Err.Description
    doc.Close
    wrd.Quit
    Exit Sub

This e-mail and any attachments are confidential and intended solely for the addressee and may also be privileged or exempt from disclosure under applicable law. If you are not the addressee, or have received this e-mail in error, please notify the sender immediately, delete it from your system and do not copy, disclose or otherwise act upon any part of this e-mail or its attachments.

Internet communications are not guaranteed to be secure or virus-free.
The Barclays Group does not accept responsibility for any loss arising from unauthorised access to, or interference with, any Internet communications by any third party, or from the transmission of any viruses. Replies to this e-mail may be monitored by the Barclays Group for operational or business reasons.

Any opinion or other information in this e-mail or its attachments that does not relate to the business of the Barclays Group is personal to the sender and is not given or endorsed by the Barclays Group.

Barclays Bank PLC.Registered in England and Wales (registered no. 1026167).
Registered Office: 1 Churchill Place, London, E14 5HP, United Kingdom.

Barclays Bank PLC is authorised and regulated by the Financial Services Authority.




More information about the AccessD mailing list