rosalyn.clarke at barclays.com
rosalyn.clarke at barclays.com
Fri Jul 25 07:52:25 CDT 2008
Hi
The only time I'm working with the word application object is to get at the
Selection property, which belongs to the application rather than the
document. Because I've defined the document as an object (or would have if
this was working), and I'm not referencing it through the application, I
don't *think* I need to reference Word when working with the document. I have
the Word object model referenced in my Access database... It's been a while
since I did much coding so I can't remember if there are differences in the
way you have to handle Word v. Excel.
I'm using 2003 by the way.
I just wish I knew why it worked on my old laptop and not this one! It not
only worked, it was very fast and I was feeling very pleased with myself, for
a little while!
Roz
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Hewson, Jim
Sent: 25 July 2008 13:40
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Programatically opening Word docs from Access
When working with Excel through Access, I need to explicitly reference Excel
or use With - End With.
Is there a reason you don't use that syntax?
Jim
jhewson at nciinc.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
rosalyn.clarke at barclays.com
Sent: Friday, July 25, 2008 6:27 AM
To: word at dcomp.com; accessd at databaseadvisors.com
Subject: [AccessD] Programatically opening Word docs from Access
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.
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
#############################################################################
###
This email transmission contains information from NCI Information Systems,
Inc.
that may be considered privileged or confidential and is intended solely for
the named recipient. If you have received this message in error, please
contact the sender immediately and be aware that the use, copying or
dissemination of this information is prohibited.
#############################################################################
###
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
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.