Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AccessのVBAでフォルダを隠しフォルダに変更

Last updated at Posted at 2020-12-06

なんで隠しフォルダに?

以下のような(ノ∀`)アチャーを防ぐ為です。

  1. Accessのプログラムが使う『一時処理用フォルダー』がユーザーでも見える状態
  2. ユーザーがそのフォルダーに重要なファイルを置いちゃう
  3. フォルダーの中身全部消すプログラムが走ってデータ消失

『隠し』にしないでユーザーがアクセスできない場所にフォルダー作ればいいじゃんアゼルバイジャンなんだけどね(´・ω・`)
そういう訳にもいかない場合があるんす…。

少しでも事故を減らす為の工夫として『隠し』化します(´・ω・`)

参照設定

この記事のサンプルでは FileSystemObject クラスを使うので、 Microsoft Scripting Runtime を参照しておく必要があります。
image.png
image.png

サンプルこーど

フォルダーパスをもらってフォルダーが存在していれば隠しフォルダ設定にするだけの単純なやつ!

Public Function hide_folder(ByVal folder_path As String)
       
    Dim fso_ As New FileSystemObject
    
    If Not fso_.FolderExists(folder_path) Then
        Exit Function
    End If
    
    fso_.GetFolder(folder_path).Attributes = Hidden

End Function

蛇足

この程度の行数なら関数化せず、スニペットに登録しておく方向もアリです。
でも関数化しておけば『隠しにしたいフォルダが存在しなかった時はログを吐く』なんて仕様変更があった時、1箇所変えるだけで済むので、改修が楽&変更漏れの心配無いです。

バージョン

Windows10 Pro バージョン1909 OSビルド19042.662
Access for Microsoft 365 MSO(16.0.13328.20334)32ビット

0
0
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?