Earlier this week I asked for a code to add a sheet to multiple workbooks. This works fine but now I learned I need to replace the sheet already with an updated one. Is there away to edit this to replace the sheet or remove the sheet and I can run the original code again?
Code:
Public Sub FixAllFiles()
FixAllFilesInDir "C:\Order\"
End Sub
Private Sub FixAllFilesInDir(ByVal pvDir)
Dim FSO, oFolder, oFile, oRX
Dim sTxt As String, sFile As String
Dim wbSrc As Workbook, wbTarg As Workbook
On Error GoTo errGetFiles
Set wbSrc = ActiveWorkbook 'source wb with the jpeg.
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(pvDir)
If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
For Each oFile In oFolder.Files
If InStr(oFile.Name, ".xlsx") > 0 Then 'import file here
sFile = oFile
Workbooks.Open sFile
Set wbTarg = ActiveWorkbook
'copy the jpg sheet to new workbook
wbSrc.Activate
wbSrc.ActiveSheet.Copy After:=wbTarg.Sheets(1)
Filename = Dir(folder & "*.xlsx", vbNormal)
wbTarg.Close True
End If
Next
endit:
Set oFile = Nothing
Set oFolder = Nothing
Set FSO = Nothing
MsgBox "Done"
Exit Sub
errGetFiles:
MsgBox Err.Description, , Err
Resume endit
Resume
End Sub