LoginSignup
2
1

More than 5 years have passed since last update.

【Excel】マクロでアウトラインの開閉を行う

Last updated at Posted at 2017-05-30

マクロでアウトラインの開閉を行っている例を調べてみると ShowDetail を使っているパターンが多かった。

Sub collapseExpand()
  Columns(1).ShowDetail = Not Columns(1).ShowDetail
End Sub

これだと1回目はうまくいくのですが、連続して実行するとShowDetailの値が変わっておらずエラーになってしまいました。

じゃあどうするのか

発想を変えて「見えなくすれば良いのでは?」ということで Hidden を使ってみました。

Sub collapseExpand()
  Columns(1).Hidden = Not Columns(1).Hidden
End Sub

無事にアウトラインの開閉が連続で行えるようになりました。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1