J
John4bank
I am trying to import employee rates from Excel into Project. The Excel file
has a column of rates and next to it a column of employee IDs. I want to
compare the EmpID fields in Project to the EmpID in fields in Excel and then
copy over the rate from Excel that corresponds to the EmpID.
I am not sure how to pull the data over from Excel though. I have included
the code that I have written so far. My problem is where the "If x = SEARCH
EXCEL LIST OF EMPLOYEE NUMBERS Then" appears in the code below. Can someone
please let me know of how I can pull this information into Project via a
macro?
Thanks,
John
Sub ImportRates()
'First enter date for rates to take affect
'Call emp# in project scan for same emp# in Excel if it exists update Std.
Rate
'If it doesn't appear in Excel highlight Red
'if it is a Material set cost to $1.06
Dim Rsr As Resource
Dim MRsr As Resources
Dim iDate As Date
Dim y As String
Dim x As String
Dim z As Integer
Dim ExcelRate As Integer
Dim BRate As Integer 'burdened base rate
Dim NRate As Integer 'no burden base rate
Dim Location As String
Set MRsr = ActiveProject.Resources
'input box to ask the user to enter the date rates should take affect
iDate = InputBox("Please enter the date the base rate should take affect.",
"Date Input", "mm/dd/yyyy")
'input box to ask the user to enter the rates for ODCs and Travel
BRate = InputBox("Please enter the rate for ODCs and Travel.", "Rate Input",
"i.e. 1.06")
'input box to ask the user to enter the rates for Materials, Subks, etc
NRate = InputBox("Please enter the rate to be used for Materials, Subks,
Consultants, and Temps.", "Rate Input", "i.e. 1.00")
'Use open Excel file
Dim xlApp As Excel.Application
Dim xlrange As Excel.Range
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If xlApp Is Nothing Then
MsgBox "Failed to connect to Excel, macro ended"
Else
MsgBox "Connected to exisitng Excel Application"
End If
xlApp.Visible = True
'Tidy up
xlApp.UserControl = True
Set xlApp = Nothing
'remove any filters on the resource sheet
If ActiveProject.AutoFilter Then
ActiveProject.AutoFilter = False ' removes any autofilters. If the list
is filtered it won't run on the undisplayed items.
End If
'go through each resource updating the Std. Rate
For Each Rsr In MRsr
y = 0 ' setting y to zero to clear it out
x = 0 ' setting x to zero to clear it out
p = Rsr.ID ' pulling in the resource id and setting it to p
SelectRow p, rowrelative:=False
SelectResourceField Row:=p, rowrelative:=False, Column:="ResourceType"
y = ActiveCell.Text 'setting y to whatever text appears in the
"ResourceType" field on the resource sheet for each individual resource
If "SAIC" = y Then ' only search for EmployeeNum of ResourceType "SAIC"
SelectRow p, rowrelative:=False
SelectResourceField Row:=p, rowrelative:=False, Column:="EmployeeNum"
x = ActiveCell.Text ' set x to employee number
If x = SEARCH EXCEL LIST OF EMPLOYEE NUMBERS Then
Rsr.CostRateTables("A").PayRates.Add iDate, ExcelRate,
ExcelRate, "0" ' changes "Std. Rate" of resources on the date entered in the
first inputbox and sets it to the rate in Excel that matches with the
employeeNum
End If
End If
If ("Travel" = y Or "ODCs" = y) Then
Rsr.CostRateTables("A").PayRates.Add iDate, BRate, BRate, "0" '
changes "Std. Rate" of resources on the date entered in the first inputbox
and sets it to the rate entered for Travel and ODCs
End If
If ("Subk" = y Or "Consultant" = y Or "Temp" = y Or "Material") Then
Rsr.CostRateTables("A").PayRates.Add iDate, NRate, NRate, "0" '
changes "Std. Rate" of resources on the date entered in the first inputbox
and sets it to the rate entered for Subk, Material, Consultant, Temp
End If
Next Rsr
End Sub
has a column of rates and next to it a column of employee IDs. I want to
compare the EmpID fields in Project to the EmpID in fields in Excel and then
copy over the rate from Excel that corresponds to the EmpID.
I am not sure how to pull the data over from Excel though. I have included
the code that I have written so far. My problem is where the "If x = SEARCH
EXCEL LIST OF EMPLOYEE NUMBERS Then" appears in the code below. Can someone
please let me know of how I can pull this information into Project via a
macro?
Thanks,
John
Sub ImportRates()
'First enter date for rates to take affect
'Call emp# in project scan for same emp# in Excel if it exists update Std.
Rate
'If it doesn't appear in Excel highlight Red
'if it is a Material set cost to $1.06
Dim Rsr As Resource
Dim MRsr As Resources
Dim iDate As Date
Dim y As String
Dim x As String
Dim z As Integer
Dim ExcelRate As Integer
Dim BRate As Integer 'burdened base rate
Dim NRate As Integer 'no burden base rate
Dim Location As String
Set MRsr = ActiveProject.Resources
'input box to ask the user to enter the date rates should take affect
iDate = InputBox("Please enter the date the base rate should take affect.",
"Date Input", "mm/dd/yyyy")
'input box to ask the user to enter the rates for ODCs and Travel
BRate = InputBox("Please enter the rate for ODCs and Travel.", "Rate Input",
"i.e. 1.06")
'input box to ask the user to enter the rates for Materials, Subks, etc
NRate = InputBox("Please enter the rate to be used for Materials, Subks,
Consultants, and Temps.", "Rate Input", "i.e. 1.00")
'Use open Excel file
Dim xlApp As Excel.Application
Dim xlrange As Excel.Range
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If xlApp Is Nothing Then
MsgBox "Failed to connect to Excel, macro ended"
Else
MsgBox "Connected to exisitng Excel Application"
End If
xlApp.Visible = True
'Tidy up
xlApp.UserControl = True
Set xlApp = Nothing
'remove any filters on the resource sheet
If ActiveProject.AutoFilter Then
ActiveProject.AutoFilter = False ' removes any autofilters. If the list
is filtered it won't run on the undisplayed items.
End If
'go through each resource updating the Std. Rate
For Each Rsr In MRsr
y = 0 ' setting y to zero to clear it out
x = 0 ' setting x to zero to clear it out
p = Rsr.ID ' pulling in the resource id and setting it to p
SelectRow p, rowrelative:=False
SelectResourceField Row:=p, rowrelative:=False, Column:="ResourceType"
y = ActiveCell.Text 'setting y to whatever text appears in the
"ResourceType" field on the resource sheet for each individual resource
If "SAIC" = y Then ' only search for EmployeeNum of ResourceType "SAIC"
SelectRow p, rowrelative:=False
SelectResourceField Row:=p, rowrelative:=False, Column:="EmployeeNum"
x = ActiveCell.Text ' set x to employee number
If x = SEARCH EXCEL LIST OF EMPLOYEE NUMBERS Then
Rsr.CostRateTables("A").PayRates.Add iDate, ExcelRate,
ExcelRate, "0" ' changes "Std. Rate" of resources on the date entered in the
first inputbox and sets it to the rate in Excel that matches with the
employeeNum
End If
End If
If ("Travel" = y Or "ODCs" = y) Then
Rsr.CostRateTables("A").PayRates.Add iDate, BRate, BRate, "0" '
changes "Std. Rate" of resources on the date entered in the first inputbox
and sets it to the rate entered for Travel and ODCs
End If
If ("Subk" = y Or "Consultant" = y Or "Temp" = y Or "Material") Then
Rsr.CostRateTables("A").PayRates.Add iDate, NRate, NRate, "0" '
changes "Std. Rate" of resources on the date entered in the first inputbox
and sets it to the rate entered for Subk, Material, Consultant, Temp
End If
Next Rsr
End Sub