×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA Open multipal files

VBA Open multipal files

VBA Open multipal files

(OP)
I need to create a VBA file so that when a user ckicks a command button it will open ALL the files of a certin type in the directory (and sub folders) searches the files for a word or words and replaces it with what the user enters in a text box on the user form.  Any ideas????\


Thanks

RE: VBA Open multipal files

What types of files are you going to be opening? If they are a specific type, it is better to call them with their native application. On the other hand, you can use the ShellExecute API call to open the file as it would from a double-click in Windows Explorer.

Declare Function ShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" (ByVal hWnd As Long, _
                       ByVal lpOperation As String, _
                       ByVal lpFile As String, _
                       ByVal lpParameters As String, _
                       ByVal lpDirectory As String, _
                       ByVal nShowCmd As Long) As Long

'To Use it
Dim hWnd As Long
Dim sFullPath As String

'sFullPath should contain the complete path and
'filename, including extension.

Call ShellExecute(hWnd, vbNullString, sFullPath, vbNullString, vbNullString, vbNormalFocus)

Let's say you are writing this in Excel VBA and want to open Excel files. I would not use the above, for you can do better using the Workbooks.Open method. If you can provide some more detail, there may be a better solution.

To do a recursive search through subdirectories, I would suggest going to the VB forum at tek-tips.com and do a search on the topic. You should look at using the FileSystemObject to retrieve a list of files of the particular type.

Hope that helps...

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: VBA Open multipal files

(OP)
DSI,

I need to open html files in a directory on a hard drive they are 4 folders deep with 1 or more html files in each directory going down, and replace a bit of imformation that is incorrect.  there is 7 of such folders and maybe 200 or more total files to be fixed.

RE: VBA Open multipal files

Will you be replacing information programmatically? If so, you may want to use the simple Open ? For Output to find and replcace text. If you just want the files to be opened, I would use the ShellExecute method. Again, for the recursive search, I would check out tek-tips.com. This issue has been covered countless times, so you will get a good flavor of different possible solutions.

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources