Hi,
I've written code in one worksheet module that I'm using to loop through multiple folders containing dozens of xls files. Each file is of the same format with multiple graphs and 3 tables of data. The charts and tables (which are linked from a second tab in the workbook) are manipulated then the active sheet is saved as a PDF file.
Everything runs fine except that I'm updating the headings on each of the 3 tables with 3 character acronyms for the department that the report is for. When I step through the code it's great, pdf saves and the proper headings are there. When I let the code run the updated headings are not there, the default title is.
I've tried everything i can think of. I ended up writing code to copy each table and pasted it over the original table, which seemed to work for a while, but that didn't last. Default titles returned.
Anyway, I'm using Excel 2010
UPDATE - I brought the files home and everything runs fine, table headings update. Must be something in the work environment?
Below is the main code, sorry for the messiness.
Dim wb As Workbook
Dim myPath As String
Dim myfile As String
Dim myextension As String
Dim strFolder As FileDialog
Dim strBase As Folder
Dim strSub As Folder
Dim strFSO As FileSystemObject
Dim xlFile As File
Dim strBranch As String
Dim strBranchFullName As String
Dim sFrench As String
'Optimize Macro Speed
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Set strFSO = New FileSystemObject
'Retrieve Target Folder Path From User
Set strFolder = Application.FileDialog(msoFileDialogFolderPicker)
With strFolder
.Title = "Select A Target Folder"
.AllowMultiSelect = False
.Show
myPath = .SelectedItems(1) & "\"
If myPath = "" Then Exit Sub
End With
Set strBase = strFSO.GetFolder(myPath)
For Each strSub In strBase.SubFolders
For Each xlFile In strSub.Files
If xlFile.Name Like "*.xls" Then
Set wb = Workbooks.Open(Filename:=xlFile.Path)
strBranch = Mid(xlFile.Name, 14, (InStr(14, xlFile.Name, "-") - 14))
If IsNumeric(Left(strBranch, 6)) Then
strBranch = Mid(strBranch, 7)
Else
strBranch = Mid(strBranch, 5)
End If
wb.Worksheets("Layout").Activate
If strBranch = "EPD" Then strBranch = "PRD"
If strBranch = "ERP" Then strBranch = "EPR"
If strBranch = "CSR" Then strBranch = "SCSR"
Range("A32") = strBranch
If Left(Right(xlFile.Name, 6), 2) = "EN" Then
Call UpdateBranchFull_ENG(strBranch, Range("A30"))
Else
Call UpdateBranchFull_FR(strBranch, Range("A30"))
sFrench = Trim(Range("A30"))
Call UPDATEBranchAcronym_FR(sFrench, Range("A32"))
End If
'************************************************************
'uPDATE CELLS WITH BRANCH ACRONYM!
'************************************************************
wb.Worksheets("Data").Activate
Cells.Select
Selection.Replace What:="BRANCH", Replacement:=strBranch, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
wb.Worksheets("Table").Activate
Range("D6").Select
ActiveCell.Value = strBranch
Range("M24").Select
ActiveCell.Value = strBranch
Range("U35").Select
ActiveCell.Value = strBranch
Range("A1").Select
wb.Worksheets("layout").Activate
Range("V6").Select
ActiveSheet.Shapes.Range(Array("Image 57")).Select
Selection.Copy
Selection.Delete
Range("V6").Select
ActiveSheet.Pictures.Paste.Select
Selection.ShapeRange.IncrementLeft 229
Selection.ShapeRange.IncrementTop -11.25
ActiveSheet.Shapes.Range(Array("Picture 59")).Select
Selection.Copy
Selection.Delete
Range("V20").Select
ActiveSheet.Pictures.Paste.Select
Selection.ShapeRange.IncrementLeft 13
Selection.ShapeRange.IncrementTop 33
Range("V20").Select
'*******************************************************
Call Template_uPDATE
'*******************************************************
'Update Charts
'*******************************************************
wb.Worksheets("layout").Activate
Call uPDATEchartlegend
wb.Worksheets("layout").Activate
Range("A1").Select
'*******************************************************
'Save and Close Workbook
'*******************************************************
wb.SaveAs xlFile
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=p & "\" & newFile & ".PDF", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'Call saveToPDF(strSub.Path, xlFile.Name)
Set wb = Nothing
End If
Next
Any thoughts.
Bookmarks