M
mablake
I am trying to code around a copy and paste issue with Word. In that
if you
copy and paste the contents of a document that has multiple sections
into an
existing document, it brings with it header and footer information. I
know
if I manually select the content of each section in turn and past
that,
headers and footers remain unaffected. I need to recreate this in
code.
Currently I use:
Sub InsertTextFromBoilerPlate()
Dim dlgOpen As FileDialog
Dim strFileLoc As String
Dim vrtSelectedItemFields As Variant
On Error Resume Next
Dim ChkResults As Variant
If
IsMissing(ActiveDocument.CustomDocumentProperties("ValidTemplate"))
Then
MsgBox "This toolbar is restricted to Valid Corporate
templates
only..."
Exit Sub
End If
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
.Filters.Add "Word Document Format", "*.doc", 1
If .Show = -1 Then
.AllowMultiSelect = False
For Each vrtSelectedItemFields In .SelectedItems
strFileLoc = vrtSelectedItemFields
Next vrtSelectedItemFields
Else
End If
End With
Set dlgOpen = Nothing
If strFileLoc = "" Then
Else
Documents.Open FileName:=strFileLoc,
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
XMLTransform:=""
Selection.WholeStory
Selection.Expand (wdMainTextStory)
Selection.Copy
ActiveDocument.Close
Selection.PasteAndFormat (wdPasteDefault)
'Selection.InsertFile FileName:=strFileLoc, Range:="", _
'ConfirmConversions:=False, Link:=False, Attachment:=False
End If
End Sub
I have experimented with selecting sections, but it always brings the
Header
and Footer. Does anyone know how to select the text within a
section,
meaning section(1) line 1 to last line of section? Or another way of
solving
this problem?
Your assistance is appreciated, Mark
if you
copy and paste the contents of a document that has multiple sections
into an
existing document, it brings with it header and footer information. I
know
if I manually select the content of each section in turn and past
that,
headers and footers remain unaffected. I need to recreate this in
code.
Currently I use:
Sub InsertTextFromBoilerPlate()
Dim dlgOpen As FileDialog
Dim strFileLoc As String
Dim vrtSelectedItemFields As Variant
On Error Resume Next
Dim ChkResults As Variant
If
IsMissing(ActiveDocument.CustomDocumentProperties("ValidTemplate"))
Then
MsgBox "This toolbar is restricted to Valid Corporate
templates
only..."
Exit Sub
End If
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
.Filters.Add "Word Document Format", "*.doc", 1
If .Show = -1 Then
.AllowMultiSelect = False
For Each vrtSelectedItemFields In .SelectedItems
strFileLoc = vrtSelectedItemFields
Next vrtSelectedItemFields
Else
End If
End With
Set dlgOpen = Nothing
If strFileLoc = "" Then
Else
Documents.Open FileName:=strFileLoc,
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
XMLTransform:=""
Selection.WholeStory
Selection.Expand (wdMainTextStory)
Selection.Copy
ActiveDocument.Close
Selection.PasteAndFormat (wdPasteDefault)
'Selection.InsertFile FileName:=strFileLoc, Range:="", _
'ConfirmConversions:=False, Link:=False, Attachment:=False
End If
End Sub
I have experimented with selecting sections, but it always brings the
Header
and Footer. Does anyone know how to select the text within a
section,
meaning section(1) line 1 to last line of section? Or another way of
solving
this problem?
Your assistance is appreciated, Mark