2016-06-15 7 views
0

に私はフッターのテキストにVBA、アライメントタブを使用して、追加しようとしてきた - これに関するコードの行は、このようなはInsertAlignmentTab()フッター

ActiveDocument.Sections(Selection.Information(wdActiveEndSectionNumber)).Footers(wdHeaderFooterPrimary).Range.Text = "Some text" & <ALIGNMENT TAB RIGHT> & "Some more text" 

ようですが、それはInsertAlignmentTab(ように見えます)メソッドは、挿入ポイントが指定された位置にある場合にのみ使用できます。挿入ポイントをフッターに移動できないため、私は目標を達成できません。

私の質問は、そこに挿入ポイントを移動せずにフッターにアライメントタブを追加する方法があるか、フッターに挿入ポイントを移動する方法があるかどうかです。

答えて

3

あなたは挿入ポイントを移動せずにこれを行うこともできます。

Sub AddAlignmentTabToFooter() 
    Dim rngFooter As Range 
    Set rngFooter = ActiveDocument.Sections(Selection.Information(wdActiveEndSectionNumber)).Footers(wdHeaderFooterPrimary).Range 
    With rngFooter 
     .Text = "Some more text" 
     .Collapse wdCollapseStart 
     .InsertAlignmentTab wdRight, wdMargin 
     .InsertBefore "Some text" 
    End With 
    Set rngFooter = Nothing 
End Sub 
1

正確に何をしたいかによって、両方を行うことができます。バックメイン文書にそれを設定するには

ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryFooter 

:主要フッタに挿入ポイントを設定するには

また

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 

InsertAlignmentTabは、任意のRangeオブジェクトで呼び出すことができます。

Selection.Range.InsertAlignmentTab wdRight, wdMargin 

まとめて入力する場合:

ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryFooter 
Selection.Range.Text = "Some more text" 
Selection.Range.InsertAlignmentTab wdRight, wdMargin 
Selection.Range.Text = "Some text" 
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 

InsertAlignmentTabコマンドは右に電流範囲を送信し、その後の選択は、少なくとも私のWord 2010環境では、左にまだあるのでSome textSome more textが、逆転していることに注意してください。)