B
Berlie
I am trying to write some VBA code that will let a user select a file
to insert into the document and then set the style of the inserted text
to a certain Style that is already defined in the template named
"Chapter Text"
The code I have works correctly some of the time but sometimes does not
work right.
When it doesn't work right it sets the Style as: "Chapter Text +
inherit, 8.5pt" instead of just "Chapter Text".
Here is the code I have:
Private Sub cmdInsertFile_Click()
Dim getName As String
Dim oRange As Range
' open File Open Dialog and get file name
With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
getName = .Name
End If
End With
' insert file, set range and set Style of range to Chapter Text
If Len(getName) > 0 Then
Set oRange = Selection.Range
Selection.InsertFile fileName:=getName
oRange.End = Selection.Range.End
oRange.Style = "Chapter Text"
Set oRange = Nothing
End If
Unload Me
End Sub
Any ideas?
Thanks in advance.
to insert into the document and then set the style of the inserted text
to a certain Style that is already defined in the template named
"Chapter Text"
The code I have works correctly some of the time but sometimes does not
work right.
When it doesn't work right it sets the Style as: "Chapter Text +
inherit, 8.5pt" instead of just "Chapter Text".
Here is the code I have:
Private Sub cmdInsertFile_Click()
Dim getName As String
Dim oRange As Range
' open File Open Dialog and get file name
With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
getName = .Name
End If
End With
' insert file, set range and set Style of range to Chapter Text
If Len(getName) > 0 Then
Set oRange = Selection.Range
Selection.InsertFile fileName:=getName
oRange.End = Selection.Range.End
oRange.Style = "Chapter Text"
Set oRange = Nothing
End If
Unload Me
End Sub
Any ideas?
Thanks in advance.