Tuesday, 17 December 2019
  0 Replies
  1.3K Visits
0
Votes
Undo
Hi Guys,
How can I get file path details with their name & extension in below code?

List all opening applications in Excel
 



Private</code></pre> <pre class="line-numbers"><code class="language-markup">Declare</code></pre> <pre class="line-numbers"><code class="language-markup">PtrSafe </code></pre><pre class="line-numbers"><code class="language-markup">Function</code></pre> <pre class="line-numbers"><code class="language-markup">apiGetClassName </code></pre><pre class="line-numbers"><code class="language-markup">Lib</code></pre> <pre class="line-numbers"><code class="language-markup">"user32"</code></pre> <pre class="line-numbers"><code class="language-markup">Alias</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">"GetClassNameA"</code></pre> <pre class="line-numbers"><code class="language-markup">(</code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">Hwnd </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">, _</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">lpClassname </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">String</code></pre><pre class="line-numbers"><code class="language-markup">, _</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">nMaxCount </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">) </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Declare</code></pre> <pre class="line-numbers"><code class="language-markup">PtrSafe </code></pre><pre class="line-numbers"><code class="language-markup">Function</code></pre> <pre class="line-numbers"><code class="language-markup">apiGetDesktopWindow </code></pre><pre class="line-numbers"><code class="language-markup">Lib</code></pre> <pre class="line-numbers"><code class="language-markup">"user32"</code></pre> <pre class="line-numbers"><code class="language-markup">Alias</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">"GetDesktopWindow"</code></pre> <pre class="line-numbers"><code class="language-markup">() </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Declare</code></pre> <pre class="line-numbers"><code class="language-markup">PtrSafe </code></pre><pre class="line-numbers"><code class="language-markup">Function</code></pre> <pre class="line-numbers"><code class="language-markup">apiGetWindow </code></pre><pre class="line-numbers"><code class="language-markup">Lib</code></pre> <pre class="line-numbers"><code class="language-markup">"user32"</code></pre> <pre class="line-numbers"><code class="language-markup">Alias</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">"GetWindow"</code></pre> <pre class="line-numbers"><code class="language-markup">(</code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">Hwnd </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">, _</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">wCmd </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">) </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Declare</code></pre> <pre class="line-numbers"><code class="language-markup">PtrSafe </code></pre><pre class="line-numbers"><code class="language-markup">Function</code></pre> <pre class="line-numbers"><code class="language-markup">apiGetWindowLong </code></pre><pre class="line-numbers"><code class="language-markup">Lib</code></pre> <pre class="line-numbers"><code class="language-markup">"user32"</code></pre> <pre class="line-numbers"><code class="language-markup">Alias</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">"GetWindowLongA"</code></pre> <pre class="line-numbers"><code class="language-markup">(</code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">Hwnd </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">, </code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">nIndex </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">) </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Declare</code></pre> <pre class="line-numbers"><code class="language-markup">PtrSafe </code></pre><pre class="line-numbers"><code class="language-markup">Function</code></pre> <pre class="line-numbers"><code class="language-markup">apiGetWindowText </code></pre><pre class="line-numbers"><code class="language-markup">Lib</code></pre> <pre class="line-numbers"><code class="language-markup">"user32"</code></pre> <pre class="line-numbers"><code class="language-markup">Alias</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">"GetWindowTextA"</code></pre> <pre class="line-numbers"><code class="language-markup">(</code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">Hwnd </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">, </code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">_</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">lpString </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">String</code></pre><pre class="line-numbers"><code class="language-markup">, </code></pre><pre class="line-numbers"><code class="language-markup">ByVal</code></pre> <pre class="line-numbers"><code class="language-markup">aint </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">) </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Const</code></pre> <pre class="line-numbers"><code class="language-markup">mcGWCHILD = 5</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Const</code></pre> <pre class="line-numbers"><code class="language-markup">mcGWHWNDNEXT = 2</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Const</code></pre> <pre class="line-numbers"><code class="language-markup">mcGWLSTYLE = (-16)</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Const</code></pre> <pre class="line-numbers"><code class="language-markup">mcWSVISIBLE = &H10000000</code></pre>
<pre class="line-numbers"><code class="language-markup">Private</code></pre> <pre class="line-numbers"><code class="language-markup">Const</code></pre> <pre class="line-numbers"><code class="language-markup">mconMAXLEN = 255</code></pre>
 
<pre class="line-numbers"><code class="language-markup">Sub</code></pre> <pre class="line-numbers"><code class="language-markup">ListName()</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Dim</code></pre> <pre class="line-numbers"><code class="language-markup">xRg </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Range</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Dim</code></pre> <pre class="line-numbers"><code class="language-markup">xStr </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">String</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Dim</code></pre> <pre class="line-numbers"><code class="language-markup">xStrLen </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Dim</code></pre> <pre class="line-numbers"><code class="language-markup">xHandle </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Dim</code></pre> <pre class="line-numbers"><code class="language-markup">xHandleStr </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">String</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Dim</code></pre> <pre class="line-numbers"><code class="language-markup">xHandleLen </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre><pre class="line-numbers"><code class="language-markup">, xHandleStyle </code></pre><pre class="line-numbers"><code class="language-markup">As</code></pre> <pre class="line-numbers"><code class="language-markup">Long</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">On</code></pre> <pre class="line-numbers"><code class="language-markup">Error</code></pre> <pre class="line-numbers"><code class="language-markup">Resume</code></pre> <pre class="line-numbers"><code class="language-markup">Next</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Set</code></pre> <pre class="line-numbers"><code class="language-markup">xRg = Application.InputBox(</code></pre><pre class="line-numbers"><code class="language-markup">"Please select a range(single cell):"</code></pre><pre class="line-numbers"><code class="language-markup">, </code></pre><pre class="line-numbers"><code class="language-markup">"KuTools For Excel"</code></pre><pre class="line-numbers"><code class="language-markup">, ActiveWindow.RangeSelection.Address, , , , , 8)</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">If</code></pre> <pre class="line-numbers"><code class="language-markup">xRg </code></pre><pre class="line-numbers"><code class="language-markup">Is</code></pre> <pre class="line-numbers"><code class="language-markup">Nothing</code></pre> <pre class="line-numbers"><code class="language-markup">Then</code></pre> <pre class="line-numbers"><code class="language-markup">Exit</code></pre> <pre class="line-numbers"><code class="language-markup">Sub</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">xRg(1).Activate</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">xHandle = apiGetWindow(apiGetDesktopWindow(), mcGWCHILD)</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Do</code></pre> <pre class="line-numbers"><code class="language-markup">While</code></pre> <pre class="line-numbers"><code class="language-markup">xHandle <> 0</code></pre>
<pre class="line-numbers"><code class="language-markup">        </code></pre><pre class="line-numbers"><code class="language-markup">xStr = </code></pre><pre class="line-numbers"><code class="language-markup">String</code></pre><pre class="line-numbers"><code class="language-markup">$(mconMAXLEN - 1, 0)</code></pre>
<pre class="line-numbers"><code class="language-markup">        </code></pre><pre class="line-numbers"><code class="language-markup">xStrLen = apiGetWindowText(xHandle, xStr, mconMAXLEN)</code></pre>
<pre class="line-numbers"><code class="language-markup">        </code></pre><pre class="line-numbers"><code class="language-markup">If</code></pre> <pre class="line-numbers"><code class="language-markup">xStrLen > 0 </code></pre><pre class="line-numbers"><code class="language-markup">Then</code></pre>
<pre class="line-numbers"><code class="language-markup">            </code></pre><pre class="line-numbers"><code class="language-markup">xStr = Left$(xStr, xStrLen)</code></pre>
<pre class="line-numbers"><code class="language-markup">            </code></pre><pre class="line-numbers"><code class="language-markup">xHandleStyle = apiGetWindowLong(xHandle, mcGWLSTYLE)</code></pre>
<pre class="line-numbers"><code class="language-markup">            </code></pre><pre class="line-numbers"><code class="language-markup">If</code></pre> <pre class="line-numbers"><code class="language-markup">xHandleStyle </code></pre><pre class="line-numbers"><code class="language-markup">And</code></pre> <pre class="line-numbers"><code class="language-markup">mcWSVISIBLE </code></pre><pre class="line-numbers"><code class="language-markup">Then</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">ActiveCell.Value = xStr</code></pre>
<pre class="line-numbers"><code class="language-markup">                </code></pre><pre class="line-numbers"><code class="language-markup">ActiveCell.Offset(1, 0).Activate</code></pre>
<pre class="line-numbers"><code class="language-markup">            </code></pre><pre class="line-numbers"><code class="language-markup">End</code></pre> <pre class="line-numbers"><code class="language-markup">If</code></pre>
<pre class="line-numbers"><code class="language-markup">        </code></pre><pre class="line-numbers"><code class="language-markup">End</code></pre> <pre class="line-numbers"><code class="language-markup">If</code></pre>
<pre class="line-numbers"><code class="language-markup">        </code></pre><pre class="line-numbers"><code class="language-markup">xHandle = apiGetWindow(xHandle, mcGWHWNDNEXT)</code></pre>
<pre class="line-numbers"><code class="language-markup">    </code></pre><pre class="line-numbers"><code class="language-markup">Loop</code></pre>
<pre class="line-numbers"><code class="language-markup">End</code></pre> <pre class="line-numbers"><code class="language-markup">Sub</code></pre>
There are no replies made for this post yet.