Query in Excel do not get latest info from Project

S

Steffen

I have the following code in order to get info to a Pivottable in Excel from
a Projectfile. It works fine when I open Excel and run the code. But if the
Excelfile is open and I then change the values in Project I cannot get the
latest data. I must close and reopen the Excelfile to get the latest data.
Can anyone give me help so updating data always works?

Steffen

Private Path As String
Private Sql_text As String

Sub Update_file()
Dim Datum As Date
Path = "Project Name=" & Range("Folder") & "\" & Range("Projectfile")
For I = 1 To 2
If I = 1 Then
Worksheets("Resources").Select
Range("Resourcestart").Select
Sql_text = "Select ResourceID, ResourceBaseCalendar,
ResourceText1 From Resources"
Get_sql
Else
Worksheets("Assignments").Select
Range("Assignmentstart").Select
Sql_text = "Select ResourceUniqueID, ResourceTimeStart,
ResourceTimeCost, ResourceTimeCumulativeCost FROM ResourceTimePhasedByMonth"
Get_sql
End If
Next I
End Sub

Sub Get_sql()
All = "OLEDB;Provider=MSDataShape.1;Extended Properties=" & Path &
";Persist Security Info=True;Initial Catalog=(Standard);Data
Provider=Microsoft Project 11.0 OLE DB Provider"
Selection.QueryTable.Connection = Array(All)
Selection.QueryTable.CommandType = xlCmdSql
Selection.QueryTable.CommandText = Array(Sql_text)
Selection.QueryTable.Refresh BackgroundQuery:=False
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top