2016-04-08 27 views
0

私はこのマクロを使用して、PDFからコピーして貼り付けたテキストを編集し、Word文書の行全体を埋めるようにします。MS Word VBA - '標準'書式設定が '見出し'書式設定によって上書きされない

ただし、ヘッダーの上に貼り付けると、Selection.Style = ActiveDocument.Styles("Normal") という行は機能せず、代わりにヘッダーとして書式設定されます。

Sub Clean_PDF_Para() 
'crude macro to fix paragraph markers (invisible)(so text copied from pdf is formatted to fill lines 
'currently based on selected range 


    With Selection.Find 
     .Text = "^p" 
     .Replacement.Text = " " 
     .Wrap = wdFindStop ' think this is required to stop it fixing (breaking) the whole selction 
    End With 

    Selection.Find.Execute Replace:=wdReplaceAll 
    Selection.Style = ActiveDocument.Styles("Normal") 'added to fix the paragraph style so it doesn't take the form of a heading. 
End Sub 

任意の助けも、

答えて

1

のみ" "が選択されている

感謝を感謝しています。段落全体を選択する必要があります:

Selection.Expand (wdParagraph) 

スタイルを設定する必要があります。

1

検索/置換の一部として使用するスタイルを含めます。 Wordは、書式設定を検索し、置換処理の一部として書式設定を適用できます。これは、コンパクターコードと間違いの可能性を低くします(選択が変更される可能性があります)。

With Selection.Find 
     .Text = "^p" 
     .Replacement.Text = " " 
     .Replacement.Style = wdStyleNormal 
     .wrap = wdFindStop ' think this is required to stop it fixing (breaking) the whole selction 
     .Execute Replace:=wdReplaceAll 
    End With