I need the macro to copy 7 htm files named, -ACH, -AHH, -FSS, -GRR..ect files located in a ACS/Test to my workbook Users\Test if sheet name is equal to -ACH, -AHH, -FSS, -GRR. Trying to do this as its a daily copy and paste for the data. I think the macro below is grabbing the files that match I just need a way to not list each directory where I am copying from as well as not list every page it is pasting to. Is this possible? There is also a pivot I run which has formulas to these documents so trying to make it a fast process. I had a macro to copy in there, but it was copying ACH to a new sheet not the existing one. I closed out and lost the macro. I am copying the whole sheet which due to htm only appears in column A.
Copy From Here Q:\ACS\Test\11-13-2017-ACH.htm
Copy From Here Q:\ACS\Test\11-13-2017-AHH.htm
Paste Here C:\Users\Test\Desktop\Book2.xlsm
These fixed widths also need applied to htm file.
Destination:=Range("A1"), DataType:=xlFixedWidth, _
OtherChar:="|", FieldInfo:=Array(Array(0, 1), Array(11, 1), Array(26, 1), Array( _
39, 1), Array(51, 1), Array(64, 1), Array(77, 1), Array(91, 1), Array(104, 1), Array(116, 1) _
), TrailingMinusNumbers:=True
Public Function IsFileOpen(strFileName As String) As Boolean
On Error Resume Next 'Ignore any errors (i.e. if workbook is not open)
Set wrkFileName = Workbooks(strFileName)
If wrkFileName Is Nothing Then
IsFileOpen = False
Else
IsFileOpen = True
End If
On Error GoTo 0 'Nullify above error handler
End Function
Sub Macro1()
Dim strDir As String, _
strFileType As String
Dim objFSO As Object, _
objFolder As Object, _
objFile As Object
Dim intCounter As Integer
strDir = "File Name" 'Change to suit
strFileType = "htm" 'Shouldn't need to, but change to suit if required
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDir)
Application.ScreenUpdating = False
For Each objFile In objFolder.Files
'If the file in the 'strDir' directory is not this workbook, then...
If objFile.Name <> ThisWorkbook.Name Then
If objFile.Name Like "*." & strFileType Then
'...check to see if it's open. If it is...
If IsFileOpen(objFile.Name) = True Then
'...run the 'MyMacro' passing the active workbook variable with it and _
increment the counter.
Call MyMacro(objFile.Name)
intCounter = intCounter + 1
'Else, _
1. Open the file, _
2. Run the 'MyMacro' passing the active workbook variable with it, _
3. Save the changes and close the file, and _
4. Increment the counter.
Else
Workbooks.Open (strDir & "\" & objFile.Name), UpdateLinks:=False
Call MyMacro(objFile.Name)
Workbooks(objFile.Name).Close SaveChanges:=True
intCounter = intCounter + 1
End If
End If
End If
'Release memory
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Next objFile
Application.ScreenUpdating = True
Select Case intCounter
Case Is = 0
MsgBox "There were no """ & strFileType & """ file types in the """ & strDir & """ directory for the desired macro to be run on.", vbExclamation, "Data Execution Editor"
Case Is = 1
MsgBox "The desired macro has been run on the only """ & strFileType & """ file in the """ & strDir & """ directory.", vbInformation, "Data Execution Editor"
Case Is > 1
MsgBox "The desired macro has now been run on the " & intCounter & " files in the """ & strDir & """ directory.", vbInformation, "Data Execution Editor"
End Select
End Sub
Sub MyMacro(strDesiredWkb As String)
(Enter Code)
MsgBox strDesiredWkb
End Sub
Bookmarks