Solved

How can vba process name and path of user selected files and folders

Posted on 2003-12-10
3
559 Views
Last Modified: 2008-02-01
For now, I only want to print the full path name of the object. Later I will add many other functions

I’ve had very little luck in my research, although getopenfilename is a little like what I want, as is a routine named WordApplicationGetOpenFileName (http://www.erlandsendata.no).

My ideal vba program would present the user with an internet explorer dialog box that lets the user browse and click to select individual files to be renamed.  The user would be able to do a scattered selection by using ctrl click.  The dialog would also have an OK/Cancel button.

For instance, if the folder structure looks like this:

Lvl1Fldra
   Lvl2FldrB   < Selected by user
      Lvl3File3-1.xls  
      Lvl3File3-2 .doc  
   Lvl2FldrC  

   Lvl2File2-1.xls < Selected  by user
   Lvl2File2-2.xls
   Lvl2File2-3.xls < Selected  by user

The vba program would print
   Selection 1 is a folder named: c:\Lvl1Fldra\lvl2FldrB
   Selection 2 is a file named: c:\Lvl1Fldra\lvl2file2-1.xls
   Selection 3 is a file named: c:\Lvl1Fldra\lvl2-3.xls
 


The vba program might be something like this pseudo code
    dim usrSel as SelectionSet
    dim ct as integer
    set usrSel = myMagicDialogFunction("Select your folders",myVbReturnCode)
    if myvbReturnCode = vbOK then
       for each obj in usrSel
           ct = ct +1
           if obj.type is a folder then
               debug.print  "selection “ & ct & “is a folder named “ & obj.name
           else
               debug.print  "selection “ & ct & “is a file named “ & obj.name
           endif
       next obj
    endif
     

An even better approach would be to add it as a function directly to Windows Explorer, perhaps as a sendto function.  I would select the files and folders, right click on the selection, then execute the program.
0
Comment
Question by:rberke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
PurplePerls earned 500 total points
ID: 9916215
You are right, the Explorer alread implements your myMagicDialogFunction() functionality.
So is the only the question how to use it?

Ok, store this script as list.vbs in the folder C:\DocumentsAndSettings\YourUserId\SendTo\list.vbs

Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
ct = 0
For I = 0 to objArgs.Count - 1
   DirFile = objArgs(I)
   ct = ct +1
   If (fso.FolderExists(DirFile)) Then
     msg = "Selection " & ct & " is a Folder: " & DirFile
   Else
     msg = "Selection " & ct & " is a File: " & DirFile
   End If
   WScript.Echo msg
Next



Give it a try.

Good luck,
PurplePerls

0
 
LVL 5

Author Comment

by:rberke
ID: 9917319
That code is very near to my goal, and is worthy of most of the points.

The only problem is that I want to use VBA inside of Excel, because I want to do lots of other processing on the objects. Many of the processes will use subroutines that I have already written in VBA.

How can I create an Excel workbook with a WorkbookOpen subroutine that does the same thing? I tried putting a TEST.xls workbook into my SendTo folder, but it does not appear on the when click on the Explorer SendTo submenu.
0
 
LVL 5

Author Comment

by:rberke
ID: 9940944
I'm giving you the full points, but I would still like suggestions on how to use VBA instead of VBS.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 91
MS Date Picker 64 bit 32 bit issue 12 72
Export PDF Form fields to Access  or Excel  in Tab order 16 129
Excel Web Add-in Where is Visual Basic used 9 81
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question