Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2016, 04:03 AM
PRA007's Avatar
PRA007 PRA007 is offline How to Loop in directory to work with all files Windows 7 64bit How to Loop in directory to work with all files Office 2010 32bit
Competent Performer
How to Loop in directory to work with all files
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default How to Loop in directory to work with all files

I am opening HTML files using following code.

Code:
Sub tester()
    Dim oFSO As Object
    Dim oFS As Object, sText As String, StrTxtT As String, StrTxtD As String, StrTxtN As String, URL As String, Rng As Range
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFS = oFSO.OpenTextFile("C:\Users\Username\Desktop\ProStrakan, Inc. et al v. Actavis Laboratories UT, Inc. et al.html")
    Dim strSource As String
    Dim strDest As String
    Do Until oFS.AtEndOfStream
        sText = oFS.ReadAll()
do some split and replace to finally get StrTxt
My problem Here is How to read all the HTML file one by one in directory and run code.
Reply With Quote
  #2  
Old 01-17-2016, 04:10 PM
macropod's Avatar
macropod macropod is offline How to Loop in directory to work with all files Windows 7 64bit How to Loop in directory to work with all files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try something based on:
Code:
Sub UpdateFiles()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.htm", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      'Process the document here
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Insert your code where the comment 'Process the document here' appears.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-17-2016, 09:04 PM
PRA007's Avatar
PRA007 PRA007 is offline How to Loop in directory to work with all files Windows 7 64bit How to Loop in directory to work with all files Office 2010 32bit
Competent Performer
How to Loop in directory to work with all files
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Solved the problem.
Reply With Quote
Reply

Tags
vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare files in different directories, slightly different namesm, Macro doesn't loop lkpederson Word VBA 0 04-28-2015 01:32 PM
How to Loop in directory to work with all files Loop through files and Copy Table Row and Paste into Different Document spiderman1369 Word VBA 2 10-15-2014 08:30 AM
How to Loop in directory to work with all files Unlink source files when creating Church Directory with INCLUDEPICTURE JohnFinNC Mail Merge 3 09-18-2014 08:50 PM
Copy Files to a directory elmnas Word VBA 8 07-11-2014 12:07 AM
How to Loop in directory to work with all files Importing Archived .pst files does not work JoJo Outlook 2 01-27-2011 12:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft