I have written a macro that opens an excel file generated from COGNOS then filters data by cost center (department), charts it and emails to the appropriate people. My dilemna is.......
It will only work as long as the user doesn't modify the base data. Since that information is coming from COGNOS the user can of course modify the recordset that is returned and then save the file. (no my IS department will not give me an ODBC connection or provide me with the passwords to the Oracle Databases).
Lets say they were to add a column .......... Well then structurally my file is not the same and it could cause issues (hehehe or Opportunities for a consultant). I am confirming that the file only contains one sheet and I am also confirming that the headings are as anticipated, its alot of coding. Is there an easier way to skin this horse? Is there something else I can check? I appreciate any input you EXPERTS could offer.
Thanks in advance.
Note AP Detail.xls is the file returned from COGNOS.
Sub LoadAPDetail()
'Clear AP Detail Sheet, we will replace with information as it comes to us from Cognos
'--------------------------------------------------------------------------------------------
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("AP Detail").Select
Cells.Select
Selection.ClearContents
Workbooks.Open Filename:="C:\Divisional Budget\AP Detail.xls"
Workbooks("AP Detail.xls").Activate
'Confirm that file is in expected format
'-------------------------------------------------------------------------------------------
If Workbooks("AP Detail.xls").Worksheets.Count > 1 Then NotAPDetail
Range("A1").Select
If ActiveCell.Value <> "Business Unit" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Deptid" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Account" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Vendor Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Vendor Name" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Descr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Voucher Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Journal Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Gl Date" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Po Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Line Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Sched Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Req Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Req Line Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Req Sched Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Invoice Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Reversal Cd" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Source" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Amount" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ProblemSheets <> "" Then MsgBox ("The AP Detail File has to be used exactly as it comes out of Cognos. Please rerun the AP Detail"), vbCritical
If ProblemSheets <> "" Then Exit Sub
'File is correct copy and add to main file
'-------------------------------------------------------------------------------------------
Stop
It will only work as long as the user doesn't modify the base data. Since that information is coming from COGNOS the user can of course modify the recordset that is returned and then save the file. (no my IS department will not give me an ODBC connection or provide me with the passwords to the Oracle Databases).
Lets say they were to add a column .......... Well then structurally my file is not the same and it could cause issues (hehehe or Opportunities for a consultant). I am confirming that the file only contains one sheet and I am also confirming that the headings are as anticipated, its alot of coding. Is there an easier way to skin this horse? Is there something else I can check? I appreciate any input you EXPERTS could offer.
Thanks in advance.
Note AP Detail.xls is the file returned from COGNOS.
Sub LoadAPDetail()
'Clear AP Detail Sheet, we will replace with information as it comes to us from Cognos
'--------------------------------------------------------------------------------------------
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("AP Detail").Select
Cells.Select
Selection.ClearContents
Workbooks.Open Filename:="C:\Divisional Budget\AP Detail.xls"
Workbooks("AP Detail.xls").Activate
'Confirm that file is in expected format
'-------------------------------------------------------------------------------------------
If Workbooks("AP Detail.xls").Worksheets.Count > 1 Then NotAPDetail
Range("A1").Select
If ActiveCell.Value <> "Business Unit" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Deptid" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Account" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Vendor Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Vendor Name" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Descr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Voucher Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Journal Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Gl Date" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Po Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Line Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Sched Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Req Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Req Line Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Req Sched Nbr" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Invoice Id" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Reversal Cd" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Source" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value <> "Amount" Then NotAPDetail
ActiveCell.Offset(0, 1).Select
If ProblemSheets <> "" Then MsgBox ("The AP Detail File has to be used exactly as it comes out of Cognos. Please rerun the AP Detail"), vbCritical
If ProblemSheets <> "" Then Exit Sub
'File is correct copy and add to main file
'-------------------------------------------------------------------------------------------
Stop