Insert file and set to certain style

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top