• ベストアンサー

【365】マクロでヘッダー・フッターが消えない

頻繁に設定するページレイアウトをマクロ化してありますが、すでにヘッダー・フッターが設定されている状態でそのマクロを実行してもヘッダー・フッターが消えません。 .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" EvenPageとFirstPageも""に設定してあります。 他に設定しなければならないマクロがあるのでしょうか?

  • KO1014
  • お礼率97% (536/551)

質問者が選んだベストアンサー

  • ベストアンサー
  • kkkkkm
  • ベストアンサー率65% (1615/2454)
回答No.1

ヘッダー/フッダーを設定する https://www.moug.net/tech/exvba/0070013.html のコードでヘッダーを作成したり手動で作成したヘッダーフッターですが、以下のようにして消えました。シートの指定はActiveSheetですが中身は同じやりかただと思います。 Sub Test() With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" End With End Sub 質問のコードに対象シートが記載されていないので上記はActiveSheet指定なのですが、印刷シート名指定でとかにするとか、シート毎の設定を全て無くしたいとかでしたら、以下のように全てのシートを対象にしないと駄目なのではないでしょうか。 Sub Test2() Dim Ws As Worksheet For Each Ws In Worksheets With Ws.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" End With Next End Sub

KO1014
質問者

お礼

ご回答ありがとうございました。 対象シートはActiveSheetです。 確かに、ご教示いただいたマクロを実行したら消えました。 ヘッダー・フッター設定のみのマクロを別途動かす必要があるのですね・・・面倒ですね。 仕方が無いので、マクロの最後に Call Test(マクロ名は後程変更) を入れることにしました。 助かりました。

関連するQ&A

  • ヘッダーのタイトルとページ表示のコードがわからない

    表のタイトルと日付、ページをヘッダーあるいはフッダーに入れたいのですが うまく表示されません。 1.左ヘッダーに【名古屋市】登録状までしか表示しません。  【名古屋市】登録状況一覧 と表示させたいです。 2.日付は出てきたのですが、作表した日付のままでしょうか?  次の日に印刷したら日付がかわるのでしょうか?  システムからダウンロードした日付をいつも表示するようにしたいです。 3.1/しか表示しません。総ページ数が表示されません。 間違っているところを指摘していただけないでしょうか? よろしくお願いします。 With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftHeader = "&""MS Pゴシック,太字""&20【&A】登録状況一覧" .CenterHeader = "" .RightHeader = Format(Date, "ggge年m月d日") & "現在" '日付 .LeftFooter = "" .CenterFooter = "&P/&N" .RightFooter = "" End With

  • ヘッダーの編集でフォントの設定をした場合は

    マクロの記録で ページ設定→ヘッダーフッター→ヘッダーの編集でフォントの設定をした場合は この設定のマクロの記録は取れないのでしょうか? マクロの記録の結果を見ても Sub Macro1() ' ' Macro11 Macro ' ' Application.PrintCommunication = False With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With Application.PrintCommunication = True ActiveSheet.PageSetup.PrintArea = "" Application.PrintCommunication = False With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "あああ" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0.590551181102362) .RightMargin = Application.InchesToPoints(0.590551181102362) .TopMargin = Application.InchesToPoints(0.78740157480315) .BottomMargin = Application.InchesToPoints(0) .HeaderMargin = Application.InchesToPoints(0) .FooterMargin = Application.InchesToPoints(0) .PrintHeadings = False .PrintGridlines = False .PrintComments = xlPrintNoComments .PrintQuality = 600 .CenterHorizontally = False .CenterVertically = False .Orientation = xlPortrait .Draft = False .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = 100 .PrintErrors = xlPrintErrorsDisplayed .OddAndEvenPagesHeaderFooter = False .DifferentFirstPageHeaderFooter = False .ScaleWithDocHeaderFooter = True .AlignMarginsHeaderFooter = True .EvenPage.LeftHeader.Text = "" .EvenPage.CenterHeader.Text = "" .EvenPage.RightHeader.Text = "" .EvenPage.LeftFooter.Text = "" .EvenPage.CenterFooter.Text = "" .EvenPage.RightFooter.Text = "" .FirstPage.LeftHeader.Text = "" .FirstPage.CenterHeader.Text = "" .FirstPage.RightHeader.Text = "" .FirstPage.LeftFooter.Text = "" .FirstPage.CenterFooter.Text = "" .FirstPage.RightFooter.Text = "" End With Application.PrintCommunication = True End Sub で、フォントの設定は見当たりません。

  • Excelでのページ番号付与について(WindowsXP)

    Excelでのページ番号付与について(WindowsXP) 何枚かのシートがあるファイルに一括でヘッダー・フッターを付けたいと思っています。 Sub SetHeader() Dim mySheet As Worksheet Application.ScreenUpdating = False For Each mySheet In ActiveWindow.SelectedSheets With mySheet.PageSetup .LeftHeader = "左ヘッダー" .CenterHeader = "中央ヘッダー" .RightHeader = "右ヘッダー" .LeftFooter = "左フッター" .CenterFooter = "中央フッター" .RightFooter = "右フッター" End With Next Application.ScreenUpdating = True End Sub 上記のようにマクロを作成したのですが、選択したシートの連番という単純な物ではなく ちょっと面倒なページ表示をしなければいけなくなりました。 一つのファイルの中で 1シート目→1ページ 2シート目→3ページ 3シート目→2ページ などとなっている場合 1枚目→1 2枚目→2-1/3    2-2/3    2-3/3 3枚目→3-1/2    3-2/2 というようなページ表示にしたいのですが、どのようにマクロを組めばいいかわからなくて困っています。 よろしくお願いいたします。  

  • 【Excel2013マクロ】コメント「なし」

    ググったところ同じ質問があったものの解決していないようなので、再度質問させていただきます。 過去の質問 → https://oshiete.goo.ne.jp/qa/9365077.html Excel2010からコピーしてきたページ設定のマクロを実行すると、コメント(M)が2010では「(なし)」だったのが2013では「シートの末尾」に設定されてしまいます。 「(なし)」でマクロを作り直してもダメです。 ------------------------------------- Application.PrintCommunication = False With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With Application.PrintCommunication = True ActiveSheet.PageSetup.PrintArea = "" Application.PrintCommunication = False With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0.78740157480315) .RightMargin = Application.InchesToPoints(0.393700787401575) .TopMargin = Application.InchesToPoints(0.393700787401575) .BottomMargin = Application.InchesToPoints(0.393700787401575) .HeaderMargin = Application.InchesToPoints(0) .FooterMargin = Application.InchesToPoints(0) .PrintHeadings = False .PrintGridlines = False .PrintComments = xlPrintNoComments .PrintQuality = 600 .CenterHorizontally = False .CenterVertically = False .Orientation = xlPortrait .Draft = False .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = False .PrintErrors = xlPrintErrorsBlank .OddAndEvenPagesHeaderFooter = False .DifferentFirstPageHeaderFooter = False .ScaleWithDocHeaderFooter = True .AlignMarginsHeaderFooter = True .EvenPage.LeftHeader.Text = "" .EvenPage.CenterHeader.Text = "" .EvenPage.RightHeader.Text = "" .EvenPage.LeftFooter.Text = "" .EvenPage.CenterFooter.Text = "" .EvenPage.RightFooter.Text = "" .FirstPage.LeftHeader.Text = "" .FirstPage.CenterHeader.Text = "" .FirstPage.RightHeader.Text = "" .FirstPage.LeftFooter.Text = "" .FirstPage.CenterFooter.Text = "" .FirstPage.RightFooter.Text = "" End With Application.PrintCommunication = True End Sub ------------------------------------- 「(なし)」にする方法はありませんか?

  • 「ヘッダーフッター」のヘッダーの文字のサイズ

    エクセルのマクロの記録で 印刷設定の ページ設定の「ヘッダーフッター」のヘッダーの 中央部に文字を入れて その文字のサイズを11から20に変更する記録を取りたいのですが 記録結果を見てみると サイズの部分が記録してないように見えます、 With ActiveSheet.PageSetup .CenterHeader = "あああ" で、ヘッダに表示する文字の記録はできています。 このような場合VBAでサイズの設定をするには どうすればいいでしょうか? 手作業で20にしても、11に戻ってしまいます。

  • エクセルのマクロについて

    エクセルの印刷マクロを作りましたが、動作が非常に遅いのです。 スタッフ用と管理者用のマクロを作り、スタッフ用が遅いのです。 余計なものが含まれているのでしょうか? お願いします。 Sub スタッフ() ' スタッフ Macro   ActiveSheet.PageSetup.PrintArea = "$A$1:$AJ$55" With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With ActiveSheet.PageSetup.PrintArea = "$A$1:$AJ$55" With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0) .RightMargin = Application.InchesToPoints(0) .TopMargin = Application.InchesToPoints(0) .BottomMargin = Application.InchesToPoints(0) .HeaderMargin = Application.InchesToPoints(0) .FooterMargin = Application.InchesToPoints(0) .PrintHeadings = False .PrintGridlines = False .PrintComments = xlPrintNoComments .CenterHorizontally = True .CenterVertically = True .Orientation = xlLandscape .Draft = False .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = 76 .PrintErrors = xlPrintErrorsDisplayed End With ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True ActiveSheet.PageSetup.PrintArea = "$A$1:$AJ$60" With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With ActiveSheet.PageSetup.PrintArea = "$A$1:$AJ$60" With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0) .RightMargin = Application.InchesToPoints(0) .TopMargin = Application.InchesToPoints(0) .BottomMargin = Application.InchesToPoints(0) .HeaderMargin = Application.InchesToPoints(0) .FooterMargin = Application.InchesToPoints(0) .PrintHeadings = False .PrintGridlines = False .PrintComments = xlPrintNoComments .CenterHorizontally = True .CenterVertically = True .Orientation = xlLandscape .Draft = False .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = 70 .PrintErrors = xlPrintErrorsDisplayed End With Range("A1").Select End Sub

  • openoffice writer ヘッダとフッタ

    openoffice writerにてページ設定をしています。書式→ページからヘッダとフッタの設定をしましたが、2ページ目のレイアウトが違うため、2ページ目で設定を変えたら全てのページでレイアウトが変わってしまいました・・。ページ毎の設定はできないのでしょうか?よろしくお願いします。

  • エクセルのマクロ;ヘッダの内容を確認する

    ヘッダの内容を簡単に確認したく、 MsgBox RightHeader, _ vbInformation, "ヘッダ確認" といったマクロを考えてみたのですが、 うまくいきません。 いちいちページ設定を確認するのが面倒なので RightHeaderの内容を簡単に確認できる方法はありますか?

  • ヘッダーとフッター

    フッターの中央にページ番号を入れたいのですが、「P.1」という形式で挿入したいのです。 「表示」「ヘッダーとフッター」で「ヘッダーとフッター」ツールバーの「ページ番号の挿入」で入れて中央そろえをするとページは入るのですが「1」としか入りません。「ページ番号の書式設定」をクリックしても番号書式には「P.1」というのはありませんでした。 方法はないのでしょうか? 教えてください。

  • Excelのマクロで実行時エラー”1004”を解決するには?

    実行時エラー”1004"で"PageSetupクラスのPrintQualityのプロパティを設定できません”となってしまいます。 モジュールは次のようになっています。 「グラフのページ設定 Sheets("Graph1").Select With ActiveChart.PageSetup .LeftHeader = "" .CenterHeader = "&F" .RightHeader = "&D" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0.787) .RightMargin = Application.InchesToPoints(0.787) .TopMargin = Application.InchesToPoints(0.984) .BottomMargin = Application.InchesToPoints(0.984) .HeaderMargin = Application.InchesToPoints(0.512) .FooterMargin = Application.InchesToPoints(0.512) .ChartSize = xlFullPage .PrintQuality = -3 .CenterHorizontally = False .CenterVertically = False .Orientation = xlLandscape .Draft = False .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .BlackAndWhite = False .Zoom = 100」 デバッグで黄色のマーカーが引いてある場所は、"PrintQuality = -3"の箇所です。 Accessのフォームからエクセルへ出力のマクロ実行ボタンを押して一連の処理が行える設定になっています。 このシステムは前任者が作成しました。 私は修正を行っているものです。 Access、Excelマクロともに初心者です。 この現象が起き始めたのは、PCがクラッシュしてデータが消えてしまったため、全てのソフトを再インストールして、バックアップのデータを設定の場所に置き直してからです。 PCがクラッシュする前は、正常に動いていました。 Accessの中身は多少いじりましたが、今、問題になっているものに結びつくものはないと思います。 解決策がお分かりになる方はいらしゃいますか? お手数をお掛けして申し訳ございませんが、どうぞ手ほどきをいただきますようお願いいたします。

専門家に質問してみよう