<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>全ファイル | nujonoa_blog</title>
	<atom:link href="https://nujonoa.com/tag/%E5%85%A8%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB/feed/" rel="self" type="application/rss+xml" />
	<link>https://nujonoa.com</link>
	<description>人生に役立つデータ集</description>
	<lastBuildDate>Fri, 05 Feb 2021 01:49:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://nujonoa.com/wp-content/uploads/2019/04/cropped-DSC00976-e1554456145409-32x32.jpg</url>
	<title>全ファイル | nujonoa_blog</title>
	<link>https://nujonoa.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【VBA】特定フォルダのファイルとシート一覧表＋ハイパーリンクを作る方法</title>
		<link>https://nujonoa.com/hyperlink-for-each-sheet/</link>
					<comments>https://nujonoa.com/hyperlink-for-each-sheet/#respond</comments>
		
		<dc:creator><![CDATA[nujonoa]]></dc:creator>
		<pubDate>Fri, 05 Feb 2021 13:45:00 +0000</pubDate>
				<category><![CDATA[マクロVBA]]></category>
		<category><![CDATA[フォルダ内]]></category>
		<category><![CDATA[全ファイル]]></category>
		<category><![CDATA[全シート]]></category>
		<category><![CDATA[エクセル]]></category>
		<category><![CDATA[セル]]></category>
		<category><![CDATA[データベース]]></category>
		<guid isPermaLink="false">http://nujonoa.com/?p=8766</guid>

					<description><![CDATA[目次 【VBA】特定フォルダのファイルとシート一覧表＋ハイパーリンクを作る方法プログラム紹介プログラムの説明まとめ 【VBA】特定フォルダのファイルとシート一覧表＋ハイパーリンクを作る方法 フォルダ内のファイル一覧は簡単 [&#8230;]]]></description>
										<content:encoded><![CDATA[

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">【VBA】特定フォルダのファイルとシート一覧表＋ハイパーリンクを作る方法</a></li><li><a href="#toc2" tabindex="0">プログラム紹介</a></li><li><a href="#toc3" tabindex="0">プログラムの説明</a></li><li><a href="#toc4" tabindex="0">まとめ</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">【VBA】特定フォルダのファイルとシート一覧表＋ハイパーリンクを作る方法</span></h2>



<p>フォルダ内のファイル一覧は簡単に取り出すことができますが、<br>フォルダ内のエクセル「シート」一覧をとりだすのは少しテクニックが要ります。</p>



<p>そこで今回は、特定のフォルダ内のエクセルのシート一覧を読み込むことができる、<br>プログラムを紹介したと思います。</p>



<h2 class="wp-block-heading"><span id="toc2">プログラム紹介</span></h2>



<p>プログラムを動かす前に、</p>



<p>①VBAの編集画面「ツール→参照」で、<br><strong>Microsoft ActiveX Data Objects 2.8 Library</strong><br>を追加して下さい。<br>②フォルダパスを検索したいパスに設定してください。<br>③「任意のセルに変更」の箇所を思い通りに変更ください。</p>



<p>※ダブルクリックでコピー</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: vb; title: ; notranslate">
Sub JIKKOU()
  
        Call DBMacro(&quot;C:\Users\bluei\OneDrive\ドキュメント\blog\fp&quot;) '←検索したいフォルダを指定する。
      
End Sub
 
Sub DBMacro(Path As String)
  
  Application.ScreenUpdating = False
  
'    Application.Calculation = xlCalculationManual '自動計算停止(手動計算)
  
    Dim objCn As New ADODB.Connection
    Dim objRS As ADODB.Recordset
    Dim sSheet As String
    Dim i      As Long
      
  
    Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    Set cf = fso.GetFolder(Path)
      
    Z = 2
      
    Cells(Z, 1) = &quot;ファイルへのパス&quot;
    Cells(Z, 2) = &quot;ファイル名&quot;
    Cells(Z, 3) = &quot;シート名&quot;
    Cells(Z, 4) = &quot;計算用&quot;
    Cells(Z, 5) = &quot;フォルダパス&quot;
    Cells(Z, 6) = &quot;シートへのリンク&quot;
    Z = Z + 1
      
    For Each sFile In cf.Files
   
    If sFile = &quot;False&quot; Then
        Exit Sub
    End If
      
    If sFile.Name Like &quot;*.xls*&quot; Then
      
    Else
        GoTo Continue
    End If
    
'db関数を使用。
    With objCn
        .Provider = &quot;Microsoft.ACE.OLEDB.12.0&quot;
        .Properties(&quot;Extended Properties&quot;) = &quot;Excel 12.0&quot;
        .Open sFile
        Set objRS = .OpenSchema(ADODB.adSchemaTables)
    End With
  
’シート名を取り出す作業
    Do Until objRS.EOF
        sSheet = objRS.Fields(&quot;TABLE_NAME&quot;).Value
        If Right(sSheet, 1) = &quot;$&quot; Or Right(sSheet, 2) = &quot;$'&quot; Then
            If Right(sSheet, 1) = &quot;$&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 1)
            End If
            If Right(sSheet, 2) = &quot;$'&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 2)
            End If
            If Left(sSheet, 1) = &quot;'&quot; Then
                sSheet = Mid(sSheet, 2)
            End If
            sSheet = Replace(sSheet, &quot;''&quot;, &quot;'&quot;)
    
'情報を張っていく。
     Application.DisplayAlerts = False
              
            Cells(Z, 1) = sFile.Path
            Cells(Z, 2) = sFile.Name
            Cells(Z, 3) = &quot;'&quot; &amp; Replace(sSheet, &quot;#&quot;, &quot;.&quot;)
              
            Cells(Z, 4) = InStrRev(Cells(Z, 1), &quot;\&quot;)
            Cells(Z, 5) = Left(Cells(Z, 1), Cells(Z, 4))
            CELLPASS = &quot;'&quot; &amp; Cells(Z, 5) &amp; &quot;&#x5B;&quot; &amp; Cells(Z, 2) &amp; &quot;]&quot; &amp; Cells(Z, 3) &amp; &quot;'!&quot;
            Cells(Z, 6) = &quot;=HYPERLINK(A&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;#&quot;&quot;&amp;C&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;!A1&quot;&quot;,&quot;&quot;リンク&quot;&quot;)&quot;
      
        Application.DisplayAlerts = True
              
            Z = Z + 1
        End If
        objRS.MoveNext
    Loop
    objRS.Close
    objCn.Close
    Set objRS = Nothing
    Set objCn = Nothing
      
        Application.StatusBar = Z
      
Continue:
    Next
 
    '子フォルダも同様に、subFolderを実行する。
    With CreateObject(&quot;Scripting.FileSystemObject&quot;)
        For Each childf In .GetFolder(Path).SubFolders
            Call DBMacro(childf.Path)
        Next
    End With
      
    Application.Calculation = xlCalculationAutomatic '自動計算開始
     
  Application.ScreenUpdating = True
      
End Sub
</pre></div>


<h2 class="wp-block-heading"><span id="toc3">プログラムの説明</span></h2>



<p>プログラムは、<br>・ADOを使って、エクセルをDBとみなして、<br>　各ファイルのシートの情報をとってくる<br>・その情報と、パスの情報を組み合わせて、ハイパーリンクを作成していく</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: vb; title: ; notranslate">
Cells(Z, 6) = &quot;=HYPERLINK(A&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;#&quot;&quot;&amp;C&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;!A1&quot;&quot;,&quot;&quot;リンク&quot;&quot;)&quot;
</pre></div>


<p>プログラムとなっています。</p>



<h2 class="wp-block-heading"><span id="toc4">まとめ</span></h2>



<p>フォルダの整理が追い付かなくなってきたら、<br>ぜひ使ってみていただけたらと思います。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nujonoa.com/hyperlink-for-each-sheet/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【VBA】ファイルを立ち上げずに、セルの情報を抜き出す方法</title>
		<link>https://nujonoa.com/how-to-extract-information-without-launching-a-file/</link>
					<comments>https://nujonoa.com/how-to-extract-information-without-launching-a-file/#respond</comments>
		
		<dc:creator><![CDATA[nujonoa]]></dc:creator>
		<pubDate>Thu, 04 Feb 2021 14:07:43 +0000</pubDate>
				<category><![CDATA[エクセル]]></category>
		<category><![CDATA[マクロVBA]]></category>
		<category><![CDATA[セル]]></category>
		<category><![CDATA[データベース]]></category>
		<category><![CDATA[フォルダ内]]></category>
		<category><![CDATA[全ファイル]]></category>
		<category><![CDATA[全シート]]></category>
		<guid isPermaLink="false">http://nujonoa.com/?p=8763</guid>

					<description><![CDATA[目次 【VBA】ファイルを立ち上げずに、エクセルの情報を抜き出す方法プログラム紹介プログラムの説明まとめ 【VBA】ファイルを立ち上げずに、エクセルの情報を抜き出す方法 エクセルで他のシートからセルの情報を持ってこようと [&#8230;]]]></description>
										<content:encoded><![CDATA[

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-4" checked><label class="toc-title" for="toc-checkbox-4">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">【VBA】ファイルを立ち上げずに、エクセルの情報を抜き出す方法</a></li><li><a href="#toc2" tabindex="0">プログラム紹介</a></li><li><a href="#toc3" tabindex="0">プログラムの説明</a></li><li><a href="#toc4" tabindex="0">まとめ</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">【VBA】ファイルを立ち上げずに、エクセルの情報を抜き出す方法</span></h2>



<p>エクセルで他のシートからセルの情報を持ってこようとすると、<br>ブックを立ち上げて、情報をコピーして、閉じてを繰り返し行う必要があります。</p>



<p>が、そんなことやっていたら日が暮れてしまいますよね。。</p>



<p>そこで今回は、ファイルを立ち上げずに、下記のように</p>



<p>・特定のフォルダ内の<br>・全ブックの<br>・全シートの<br>・特定のセルの情報<br>を持ってくる方法を紹介したいと思います。</p>



<figure class="wp-block-image size-large"><a rel="noopener" target="_blank" href="https://nujonoa.com/wp-content/uploads/2021/01/image-50.png"><img fetchpriority="high" decoding="async" width="900" height="518" src="https://nujonoa.com/wp-content/uploads/2021/01/image-50-900x518.png" alt="フォルダ内の全ファイル全シートの情報を抜き出す。" class="wp-image-8598" srcset="https://nujonoa.com/wp-content/uploads/2021/01/image-50-900x518.png 900w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-500x288.png 500w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-300x173.png 300w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-768x442.png 768w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-120x68.png 120w, https://nujonoa.com/wp-content/uploads/2021/01/image-50.png 972w" sizes="(max-width: 900px) 100vw, 900px" /></a></figure>



<h2 class="wp-block-heading"><span id="toc2">プログラム紹介</span></h2>



<p>プログラムを動かす前に、</p>



<p>①VBAの編集画面「ツール→参照」で、<br><strong>Microsoft ActiveX Data Objects 2.8 Library</strong><br>を追加して下さい。<br>②フォルダパスを検索したいパスに設定してください。<br>③「任意のセルに変更」の箇所を思い通りに変更ください。</p>



<p>※ダブルクリックでコピーできます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: vb; title: ; notranslate">
Sub JIKKOU()
 
        Call DBMacro(&quot;C:\Users\bluei\OneDrive\ドキュメント\blog\fp&quot;) '←検索したいフォルダを指定する。
     
End Sub

Sub DBMacro(Path As String)
 
  Application.ScreenUpdating = False
 
'    Application.Calculation = xlCalculationManual '自動計算停止(手動計算)
 
    Dim objCn As New ADODB.Connection
    Dim objRS As ADODB.Recordset
    Dim sSheet As String
    Dim i      As Long
     
 
    Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    Set cf = fso.GetFolder(Path)
     
    Z = 2
     
    Cells(Z, 1) = &quot;ファイルへのパス&quot;
    Cells(Z, 2) = &quot;ファイル名&quot;
    Cells(Z, 3) = &quot;シート名&quot;
    Cells(Z, 4) = &quot;計算用&quot;
    Cells(Z, 5) = &quot;フォルダパス&quot;
    Cells(Z, 6) = &quot;シートへのリンク&quot;
    Cells(Z, 7) = &quot;ここからセルの値⇒⇒&quot;
    Z = Z + 1
     
    For Each sFile In cf.Files
  
    If sFile = &quot;False&quot; Then
        Exit Sub
    End If
     
    If sFile.Name Like &quot;*.xls*&quot; Then
     
    Else
        GoTo Continue
    End If
   
'db関数を使用。
    With objCn
        .Provider = &quot;Microsoft.ACE.OLEDB.12.0&quot;
        .Properties(&quot;Extended Properties&quot;) = &quot;Excel 12.0&quot;
        .Open sFile
        Set objRS = .OpenSchema(ADODB.adSchemaTables)
    End With
 
’シート名を取り出す作業
    Do Until objRS.EOF
        sSheet = objRS.Fields(&quot;TABLE_NAME&quot;).Value
        If Right(sSheet, 1) = &quot;$&quot; Or Right(sSheet, 2) = &quot;$'&quot; Then
            If Right(sSheet, 1) = &quot;$&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 1)
            End If
            If Right(sSheet, 2) = &quot;$'&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 2)
            End If
            If Left(sSheet, 1) = &quot;'&quot; Then
                sSheet = Mid(sSheet, 2)
            End If
            sSheet = Replace(sSheet, &quot;''&quot;, &quot;'&quot;)
   
'情報を張っていく。
     Application.DisplayAlerts = False
             
            Cells(Z, 1) = sFile.Path
            Cells(Z, 2) = sFile.Name
            Cells(Z, 3) = &quot;'&quot; &amp; Replace(sSheet, &quot;#&quot;, &quot;.&quot;)
             
            Cells(Z, 4) = InStrRev(Cells(Z, 1), &quot;\&quot;)
            Cells(Z, 5) = Left(Cells(Z, 1), Cells(Z, 4))
            CELLPASS = &quot;'&quot; &amp; Cells(Z, 5) &amp; &quot;&#x5B;&quot; &amp; Cells(Z, 2) &amp; &quot;]&quot; &amp; Cells(Z, 3) &amp; &quot;'!&quot;
            Cells(Z, 6) = &quot;=HYPERLINK(A&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;#&quot;&quot;&amp;C&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;!A1&quot;&quot;,&quot;&quot;リンク&quot;&quot;)&quot;
             
            Cells(Z, 7) = &quot;=&quot; &amp; CELLPASS &amp; &quot;F6&quot;  '任意のセルに変更
            Cells(Z, 8) = &quot;=&quot; &amp; CELLPASS &amp; &quot;Y6&quot;  '任意のセルに変更
            Cells(Z, 9) = &quot;=&quot; &amp; CELLPASS &amp; &quot;M9&quot;  '任意のセルに変更
            Cells(Z, 10) = &quot;=&quot; &amp; CELLPASS &amp; &quot;M15&quot;  '任意のセルに変更
            Cells(Z, 11) = &quot;=&quot; &amp; CELLPASS &amp; &quot;E19&quot;  '任意のセルに変更
            Cells(Z, 12) = &quot;=&quot; &amp; CELLPASS &amp; &quot;B26&quot;  '任意のセルに変更
            Cells(Z, 13) = &quot;=&quot; &amp; CELLPASS &amp; &quot;I26&quot;  '任意のセルに変更
            Cells(Z, 14) = &quot;=&quot; &amp; CELLPASS &amp; &quot;P26&quot;  '任意のセルに変更
            Cells(Z, 15) = &quot;=&quot; &amp; CELLPASS &amp; &quot;B28&quot;  '任意のセルに変更

 
            DoEvents  '重すぎるのでフリーズしないように入れる。
 
'シートをリンクさせないバージョン↓
'            Cells(Z, 8).Value = ExecuteExcel4Macro(&quot;'&quot; &amp; Cells(Z, 5) &amp; &quot;&#x5B;&quot; &amp; Cells(Z, 2) &amp; &quot;]&quot; &amp; Cells(Z, 3) &amp; &quot;'!R26C2&quot;)
             
             
        Application.DisplayAlerts = True
             
             
            Z = Z + 1
        End If
        objRS.MoveNext
    Loop
    objRS.Close
    objCn.Close
    Set objRS = Nothing
    Set objCn = Nothing
     
        Application.StatusBar = Z
     
Continue:
    Next

    '子フォルダも同様に、subFolderを実行する。
    With CreateObject(&quot;Scripting.FileSystemObject&quot;)
        For Each childf In .GetFolder(Path).SubFolders
            Call DBMacro(childf.Path)
        Next
    End With
     
    Application.Calculation = xlCalculationAutomatic '自動計算開始
    
    Range(Cells(1, 1), Cells(Z, 30)).Formula = Range(Cells(1, 1), Cells(Z, 30)).Formula
    
  Application.ScreenUpdating = True
     
End Sub


</pre></div>


<h2 class="wp-block-heading"><span id="toc3">プログラムの説明</span></h2>



<p></p>



<p>ADOを使って、エクセルをDBとみなして、<br>各ファイルのシートをすべてとってきています。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: vb; title: ; notranslate">
'db関数を使用。
    With objCn
        .Provider = &quot;Microsoft.ACE.OLEDB.12.0&quot;
        .Properties(&quot;Extended Properties&quot;) = &quot;Excel 12.0&quot;
        .Open sFile
        Set objRS = .OpenSchema(ADODB.adSchemaTables)
    End With
 
’シート名を取り出す作業
    Do Until objRS.EOF
        sSheet = objRS.Fields(&quot;TABLE_NAME&quot;).Value
        If Right(sSheet, 1) = &quot;$&quot; Or Right(sSheet, 2) = &quot;$'&quot; Then
            If Right(sSheet, 1) = &quot;$&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 1)
            End If
            If Right(sSheet, 2) = &quot;$'&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 2)
            End If
            If Left(sSheet, 1) = &quot;'&quot; Then
                sSheet = Mid(sSheet, 2)
            End If
            sSheet = Replace(sSheet, &quot;''&quot;, &quot;'&quot;)
</pre></div>


<p>その情報を使って、<br>・そのブックにリンクを作っていきます。<br>【＝'パス名[ブック名]シート名'セル名】<br>例)='C:\Users\bluei\OneDrive\ドキュメント\blog\fp[(201912)簡易FP.xlsx]→'!F6】</p>



<p>他のファイルで↓の表示が出ると、かなり萎えますが、今回の場合は、これを思う存分行うようにしています。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a rel="noopener" target="_blank" href="https://nujonoa.com/wp-content/uploads/2021/01/image-51.png"><img decoding="async" width="726" height="138" src="https://nujonoa.com/wp-content/uploads/2021/01/image-51.png" alt="安全ではない可能性のある外部ソースへのリンクが" class="wp-image-8600" srcset="https://nujonoa.com/wp-content/uploads/2021/01/image-51.png 726w, https://nujonoa.com/wp-content/uploads/2021/01/image-51-500x95.png 500w, https://nujonoa.com/wp-content/uploads/2021/01/image-51-300x57.png 300w" sizes="(max-width: 726px) 100vw, 726px" /></a></figure></div>



<p>そのまま数式は残してありますが、最後にコピーして値貼り付けをすれば、<br>このリンクは削除できますので、変に重たいファイルになることを防ぐことも可能です。</p>



<h2 class="wp-block-heading"><span id="toc4">まとめ</span></h2>



<p>暗黙知を形式知にしたり、情報の共有を図るために、</p>



<p>・何かしらのフォーマットにある程度のルールにのっとったファイル</p>



<p>を作っていくことがあると思いますが、<br>残念ながらそれがうまく活用されることが少ないように感じます。</p>



<p>そのハードルを下げるためにも、誰もが使っているエクセルで、<br>DBを作ることに意味はあると思います。</p>



<p>是非検討してみてください！！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nujonoa.com/how-to-extract-information-without-launching-a-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【エクセルDB】フォルダ内の全ファイル全シートのセルの情報を書き出す。</title>
		<link>https://nujonoa.com/extract-cell-information-of-all-files-and-all-sheets/</link>
					<comments>https://nujonoa.com/extract-cell-information-of-all-files-and-all-sheets/#respond</comments>
		
		<dc:creator><![CDATA[nujonoa]]></dc:creator>
		<pubDate>Sat, 23 Jan 2021 13:53:11 +0000</pubDate>
				<category><![CDATA[エクセル]]></category>
		<category><![CDATA[google spreadsheet]]></category>
		<category><![CDATA[セル]]></category>
		<category><![CDATA[データベース]]></category>
		<category><![CDATA[フォルダ内]]></category>
		<category><![CDATA[全ファイル]]></category>
		<category><![CDATA[全シート]]></category>
		<guid isPermaLink="false">http://nujonoa.com/?p=8184</guid>

					<description><![CDATA[目次 【エクセルDB】フォルダ内の全ファイル全シートの情報を書き出す。プログラム紹介プログラムの説明まとめ 【エクセルDB】フォルダ内の全ファイル全シートの情報を書き出す。 エクセルは時代遅れ、、、といわれながらも、社内 [&#8230;]]]></description>
										<content:encoded><![CDATA[

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-6" checked><label class="toc-title" for="toc-checkbox-6">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">【エクセルDB】フォルダ内の全ファイル全シートの情報を書き出す。</a></li><li><a href="#toc2" tabindex="0">プログラム紹介</a></li><li><a href="#toc3" tabindex="0">プログラムの説明</a></li><li><a href="#toc4" tabindex="0">まとめ</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">【エクセルDB】フォルダ内の全ファイル全シートの情報を書き出す。</span></h2>



<p>エクセルは時代遅れ、、、といわれながらも、<br>社内外のやり取りはエクセルで行われるのが主ですし、<br>これからもそれがどっと変わることはないでしょう。<br>※スプレッドシートはありかなと思うのですが…<br>　結局なんやかんや表計算ソフトは便利です。</p>



<p>そこで、今回はエクセルデータベースをVBAで無理やり作ってみました。</p>



<p>出来ることは、下記画像の通り、<br><strong>対象のフォルダ内のエクセルシートの</strong><br>・ファイルのパス<br>・エクセルのファイル名<br>・エクセルのシート名<br>・そのシートへのリンク<br>・そのシートの対象のセルの値を読み込む。</p>



<figure class="wp-block-image size-large"><a rel="noopener" target="_blank" href="https://nujonoa.com/wp-content/uploads/2021/01/image-50.png"><img decoding="async" width="900" height="518" src="https://nujonoa.com/wp-content/uploads/2021/01/image-50-900x518.png" alt="フォルダ内の全ファイル全シートの情報を抜き出す。" class="wp-image-8598" srcset="https://nujonoa.com/wp-content/uploads/2021/01/image-50-900x518.png 900w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-500x288.png 500w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-300x173.png 300w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-768x442.png 768w, https://nujonoa.com/wp-content/uploads/2021/01/image-50-120x68.png 120w, https://nujonoa.com/wp-content/uploads/2021/01/image-50.png 972w" sizes="(max-width: 900px) 100vw, 900px" /></a></figure>



<p>というプログラムです。</p>



<p>フォルダと、セルの値だけ変えてもらえればすぐに使えますので、<br>ぜひ参考にしてみてください！！！</p>



<h2 class="wp-block-heading"><span id="toc2">プログラム紹介</span></h2>



<p>プログラムを動かす前に、</p>



<p>①VBAの編集画面「ツール→参照」で、<br><strong>Microsoft ActiveX Data Objects 2.8 Library</strong><br>を追加して下さい。<br>②フォルダパスを検索したいパスに設定してください。<br>③「任意のセルに変更」の箇所を思い通りに変更ください。</p>



<p>それが出来たら実行してください。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: vb; title: ; notranslate">
Sub DBMacro(Path As String)
 
  Application.ScreenUpdating = False
 
'    Application.Calculation = xlCalculationManual '自動計算停止(手動計算)
 
    Dim objCn As New ADODB.Connection
    Dim objRS As ADODB.Recordset
    Dim sSheet As String
    Dim i      As Long
     
 
    Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    Set cf = fso.GetFolder(Path)
     
    Z = 2
     
    Cells(Z, 1) = &quot;ファイルへのパス&quot;
    Cells(Z, 2) = &quot;ファイル名&quot;
    Cells(Z, 3) = &quot;シート名&quot;
    Cells(Z, 4) = &quot;計算用&quot;
    Cells(Z, 5) = &quot;フォルダパス&quot;
    Cells(Z, 6) = &quot;シートへのリンク&quot;
    Cells(Z, 7) = &quot;ここからセルの値⇒⇒&quot;
    Z = Z + 1
     
     
     
    '直下
     
    For Each sFile In cf.Files
     
  
    If sFile = &quot;False&quot; Then
        Exit Sub
    End If
     
    If sFile.Name Like &quot;*.xls*&quot; Then
     
    Else
        GoTo Continue
    End If
   
    With objCn
        .Provider = &quot;Microsoft.ACE.OLEDB.12.0&quot;
        .Properties(&quot;Extended Properties&quot;) = &quot;Excel 12.0&quot;
        .Open sFile
        Set objRS = .OpenSchema(ADODB.adSchemaTables)
    End With
 
    Do Until objRS.EOF
        sSheet = objRS.Fields(&quot;TABLE_NAME&quot;).Value
        If Right(sSheet, 1) = &quot;$&quot; Or Right(sSheet, 2) = &quot;$'&quot; Then
            If Right(sSheet, 1) = &quot;$&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 1)
            End If
            If Right(sSheet, 2) = &quot;$'&quot; Then
                sSheet = Left(sSheet, Len(sSheet) - 2)
            End If
            If Left(sSheet, 1) = &quot;'&quot; Then
                sSheet = Mid(sSheet, 2)
            End If
            sSheet = Replace(sSheet, &quot;''&quot;, &quot;'&quot;)
        Application.DisplayAlerts = False
             
            Cells(Z, 1) = sFile.Path
            Cells(Z, 2) = sFile.Name
            Cells(Z, 3) = &quot;'&quot; &amp; Replace(sSheet, &quot;#&quot;, &quot;.&quot;)
             
            Cells(Z, 4) = InStrRev(Cells(Z, 1), &quot;\&quot;)
            Cells(Z, 5) = Left(Cells(Z, 1), Cells(Z, 4))
            CELLPASS = &quot;'&quot; &amp; Cells(Z, 5) &amp; &quot;&#x5B;&quot; &amp; Cells(Z, 2) &amp; &quot;]&quot; &amp; Cells(Z, 3) &amp; &quot;'!&quot;
            Cells(Z, 6) = &quot;=HYPERLINK(A&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;#&quot;&quot;&amp;C&quot; &amp; Z &amp; &quot;&amp;&quot;&quot;!A1&quot;&quot;,&quot;&quot;リンク&quot;&quot;)&quot;
             
            Cells(Z, 7) = &quot;=&quot; &amp; CELLPASS &amp; &quot;F6&quot;  '任意のセルに変更
            Cells(Z, 8) = &quot;=&quot; &amp; CELLPASS &amp; &quot;Y6&quot;  '任意のセルに変更
            Cells(Z, 9) = &quot;=&quot; &amp; CELLPASS &amp; &quot;M9&quot;  '任意のセルに変更
            Cells(Z, 10) = &quot;=&quot; &amp; CELLPASS &amp; &quot;M15&quot;  '任意のセルに変更
            Cells(Z, 11) = &quot;=&quot; &amp; CELLPASS &amp; &quot;E19&quot;  '任意のセルに変更
            Cells(Z, 12) = &quot;=&quot; &amp; CELLPASS &amp; &quot;B26&quot;  '任意のセルに変更
            Cells(Z, 13) = &quot;=&quot; &amp; CELLPASS &amp; &quot;I26&quot;  '任意のセルに変更
            Cells(Z, 14) = &quot;=&quot; &amp; CELLPASS &amp; &quot;P26&quot;  '任意のセルに変更
            Cells(Z, 15) = &quot;=&quot; &amp; CELLPASS &amp; &quot;B28&quot;  '任意のセルに変更
            Cells(Z, 16) = &quot;=&quot; &amp; CELLPASS &amp; &quot;I28&quot;  '任意のセルに変更
            Cells(Z, 17) = &quot;=&quot; &amp; CELLPASS &amp; &quot;N28&quot;  '任意のセルに変更
            Cells(Z, 18) = &quot;=&quot; &amp; CELLPASS &amp; &quot;I29&quot;  '任意のセルに変更
            Cells(Z, 19) = &quot;=&quot; &amp; CELLPASS &amp; &quot;P29&quot;  '任意のセルに変更
            Cells(Z, 20) = &quot;=&quot; &amp; CELLPASS &amp; &quot;W26&quot;  '任意のセルに変更
            Cells(Z, 21) = &quot;=&quot; &amp; CELLPASS &amp; &quot;AD26&quot;  '任意のセルに変更
            Cells(Z, 22) = &quot;=&quot; &amp; CELLPASS &amp; &quot;AK26&quot;  '任意のセルに変更
            Cells(Z, 23) = &quot;=&quot; &amp; CELLPASS &amp; &quot;W28&quot;  '任意のセルに変更
            Cells(Z, 24) = &quot;=&quot; &amp; CELLPASS &amp; &quot;AD28&quot;  '任意のセルに変更
            Cells(Z, 25) = &quot;=&quot; &amp; CELLPASS &amp; &quot;AI28&quot;  '任意のセルに変更
            Cells(Z, 26) = &quot;=&quot; &amp; CELLPASS &amp; &quot;AD29&quot;  '任意のセルに変更
            Cells(Z, 27) = &quot;=&quot; &amp; CELLPASS &amp; &quot;AK29&quot;  '任意のセルに変更
 
            DoEvents  '重すぎるのでフリーズしないように入れる。
 
'シートをリンクさせないバージョン↓
'            Cells(Z, 8).Value = ExecuteExcel4Macro(&quot;'&quot; &amp; Cells(Z, 5) &amp; &quot;&#x5B;&quot; &amp; Cells(Z, 2) &amp; &quot;]&quot; &amp; Cells(Z, 3) &amp; &quot;'!R26C2&quot;)
             
             
        Application.DisplayAlerts = True
             
             
            Z = Z + 1
        End If
        objRS.MoveNext
    Loop
    objRS.Close
    objCn.Close
    Set objRS = Nothing
    Set objCn = Nothing
     
        Application.StatusBar = Z
     
Continue:
    Next

    '子フォルダも同様に、subFolderを実行する。
    With CreateObject(&quot;Scripting.FileSystemObject&quot;)
        For Each childf In .GetFolder(Path).SubFolders
            Call DBMacro(childf.Path)
        Next
    End With
     
    Application.Calculation = xlCalculationAutomatic '自動計算開始
    
    
    
    Range(Cells(1, 1), Cells(Z, 30)).Formula = Range(Cells(1, 1), Cells(Z, 30)).Formula
    
  Application.ScreenUpdating = True
     
End Sub

Sub JIKKOU()
 
        Call DBMacro(&quot;C:\Users\bluei\OneDrive\ドキュメント\blog\fp&quot;) '←検索したいフォルダを指定する。
     
End Sub

</pre></div>


<h2 class="wp-block-heading"><span id="toc3">プログラムの説明</span></h2>



<p>長すぎるので、説明は端折りますが、</p>



<p>・ファイルを検索して、<br>・ファイルがエクセルの場合、その中のシートを全部読み取りハイパーリンクを作成がてら、<br>・そのシートの特定のセルへ【='C:\Users\bluei\OneDrive\ドキュメント\blog\fp[(201912)簡易FP.xlsx]→'!F6】みたいな外部リンクの数式をじゃんじゃん作っていく。</p>



<p>イメージです。</p>



<p>よくある悪者</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a rel="noopener" target="_blank" href="https://nujonoa.com/wp-content/uploads/2021/01/image-51.png"><img loading="lazy" decoding="async" width="726" height="138" src="https://nujonoa.com/wp-content/uploads/2021/01/image-51.png" alt="安全ではない可能性のある外部ソースへのリンクが" class="wp-image-8600" srcset="https://nujonoa.com/wp-content/uploads/2021/01/image-51.png 726w, https://nujonoa.com/wp-content/uploads/2021/01/image-51-500x95.png 500w, https://nujonoa.com/wp-content/uploads/2021/01/image-51-300x57.png 300w" sizes="(max-width: 726px) 100vw, 726px" /></a></figure></div>



<p>を逆に存分に使ってやろうという感じになります。<br>そのまま数式は残してありますが、最後にコピーして値貼り付けをすれば、<br>このリンクは削除できますので、変に重たいファイルになることを防ぐことも可能です。</p>



<h2 class="wp-block-heading"><span id="toc4">まとめ</span></h2>



<p>結構苦労してたどり着いたプログラムなので、<br>かわいがってやってください。</p>



<p>何か要望などあれば、コメントへどうぞ！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nujonoa.com/extract-cell-information-of-all-files-and-all-sheets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
