Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Open multipal files

Status
Not open for further replies.

mustangcoupe

Electrical
Nov 13, 2002
10
0
0
US
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
 
Replies continue below

Recommended for you

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.
Code:
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.
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top