Is there a way to change or add a reference to a template for a Word document?
The reason I ask is that we have code that copies in our firm styles to documents created before those firm styles existed. It isn't working, however, for documents created from the scanner or emailed to us. At that point we get a
Microsoft Visual Basic
Run-time error '9541':
The requested member of the collection does not exist.
I am over my head on this one, but the firm does not want to pay developer costs...
I have no idea where goFormsAssistant is getting methods or properties. I don't see any objects in this project.Code:Sub CopyFirmStyles() UpdateNStyles If Not InstantiateFormsAssistantUI() Then Exit Sub goFormsAssistant.CopyFirmStylesFromBlankTemplate End Sub Sub UpdateNStyles() 'I wrote this RenameNstyles CopyNstyles End Sub Sub RenameNstyles() 'I wrote this 'Renames the existing NCHC styles to N... Dim OGstyleName As String Dim NewStyleName As String Dim ChangeStyle As Style Dim StylePrefix As String StylePrefix = "NCHC" For Each ChangeStyle In ActiveDocument.Styles 'reduce the number of loops by only checking paragraph styles If ChangeStyle.Type = wdStyleTypeParagraph Then OGstyleName = ChangeStyle.NameLocal If (InStr(1, OGstyleName, StylePrefix, 1) = 1) Then NewStyleName = Mid(OGstyleName, 5) NewStyleName = "N" & NewStyleName ChangeStyle.NameLocal = NewStyleName End If End If Next ChangeStyle End Sub Sub CopyNstyles() Dim Blankdot As Document Dim Thisdot As Document Dim NewStyleName As String Dim CurrentStyleName As String Dim AddStyle As Style Dim StylePrefix As String Dim TemplateString As String Dim StartNInt As Integer Dim EndNInt As Integer Dim NIntFound As Integer Dim CounterInt As Integer Dim IntHolder As Integer Dim MIntFound As Integer Dim TestInt As Integer TestInt = 0 NIntFound = 0 StartNInt = 1 StylePrefix = "N " MIntFound = 0 Set Thisdot = ActiveDocument 'modified for citrix compatibility TemplateString = FullTemplatePath("Blank.dot") 'changed to make the file invisible and not add to list of recent files Set Blankdot = Documents.Open(TemplateString, , , False, , , , , , , , False) EndNInt = Blankdot.Styles.Count Documents(Thisdot).Activate 'Look for styles in blank.dot that are appended with "N " For Each AddStyle In Blankdot.Styles 'Test for style found in current template TestInt = 0 NewStyleName = AddStyle.NameLocal If (InStr(1, NewStyleName, StylePrefix, 1) = 1) Then 'Look for this same style in the current template For CounterInt = StartNInt To EndNInt 'In Thisdot.Styles CurrentStyleName = Thisdot.Styles(CounterInt).NameLocal 'Test to see if this should be our starting point from henceforward If NIntFound = 0 Then If (InStr(1, CurrentStyleName, StylePrefix, 1) = 1) Then NIntFound = 1 IntHolder = CounterInt End If Else 'Test to see if this should be our ending point from henceforward If MIntFound = 0 Then If (InStr(1, CurrentStyleName, StylePrefix, 1) <> 1) Then IntHolder = CounterInt EndNInt = IntHolder MIntFound = 1 End If End If End If If CurrentStyleName = NewStyleName Then 'Style was found in current template, so exit loop & flag style as found TestInt = 1 Exit For End If Next CounterInt 'If style not found in current template, then copy it in If TestInt = 0 Then Application.OrganizerCopy Source:= _ TemplateString, Destination _ :=Thisdot.AttachedTemplate.FullName, Name:=NewStyleName, Object:= _ wdOrganizerObjectStyles End If End If If NIntFound = 1 Then StartNInt = IntHolder End If Next AddStyle Documents(Blankdot).Close Documents(Thisdot).Activate End Sub Function InstantiateFormsAssistantUI() As Boolean 'I did not write this If DEBUG_MODE Then On Error GoTo 0 Else On Error GoTo ErrorHandler InstantiateFormsAssistantUI = True If Not (goFormsAssistant Is Nothing) Then Exit Function End If ''' Set goFormsAssistant = New pcgFormsAssistant.UI Set goFormsAssistant = CreateObject("pcgFormsAssistant.UI") goFormsAssistant.SetWord Application Exit Function ErrorHandler: MsgBox "An unexpected error has been encountered." & vbCr & vbCr & _ Err.Number & ": " & Err.Description, vbExclamation + vbOKOnly, "Forms Assistant" InstantiateFormsAssistantUI = False End Function Public goFormsAssistant As Object ' pcgFormsAssistant.UI 'I did not write this![]()




Reply With Quote