Hi </SPAN></SPAN>
I have some code that I am using to Open a Microsoft Project file but despite all efforts I have been unable to prevent the opening dialogue box from appearing or auto answering it.</SPAN>
i.e. "Open resource pool read-only allowing others to work on projects connected to the pool"</SPAN></SPAN>
I have tried "Application.EnableEvents = False", "Application.DisplayAlaerts = False" and .FileOpenEx all to no avail.</SPAN></SPAN>
I would appreciate some help. Thanks in advance.</SPAN></SPAN>
</SPAN></SPAN>
I have some code that I am using to Open a Microsoft Project file but despite all efforts I have been unable to prevent the opening dialogue box from appearing or auto answering it.</SPAN>
i.e. "Open resource pool read-only allowing others to work on projects connected to the pool"</SPAN></SPAN>
I have tried "Application.EnableEvents = False", "Application.DisplayAlaerts = False" and .FileOpenEx all to no avail.</SPAN></SPAN>
I would appreciate some help. Thanks in advance.</SPAN></SPAN>
Code:
Public Sub extract_data()</SPAN></SPAN>
Dim appProj As MSProject.Application</SPAN></SPAN>
Dim aProg As MSProject.Project</SPAN></SPAN>
Dim app</SPAN></SPAN>
Dim mppApp As MSProject.Application</SPAN></SPAN>
Dim Tasks As Tasks</SPAN></SPAN>
Dim mpp_file_name As String</SPAN></SPAN>
Dim j As Integer</SPAN></SPAN>
Set destination_ws = ThisWorkbook.Worksheets("Imported Vehicles")</SPAN></SPAN>
destination_ws.Cells.Clear</SPAN></SPAN>
file_location = ThisWorkbook.Worksheets("Control Panel").Range("F19").Value</SPAN></SPAN>
file_name = ThisWorkbook.Worksheets("Control Panel").Range("F20").Value</SPAN></SPAN>
file_location_and_name = file_location & file_name</SPAN></SPAN>
Set appProj = CreateObject("Msproject.Application")</SPAN></SPAN>
'---------------------------------------------------------------------</SPAN></SPAN>
'Set appProj = GetObject(, "MSProject.Application")</SPAN></SPAN>
'If IsEmpty(appProj) Then Set appProj = CreateObject("MSProject.Application")</SPAN></SPAN>
'appProj.FileOpenEx Name:=file_location_and_name, ReadOnly:=True</SPAN></SPAN>
'---------------------------------------------------------------------</SPAN></SPAN>
Application.EnableEvents = True</SPAN></SPAN>
Set mppApp = CreateObject("msproject.application")</SPAN></SPAN>
mppApp.DisplayAlerts = False</SPAN></SPAN>
mppApp.FileOpen Name:=file_location_and_name, ReadOnly:=True ' Opens file as Read Only</SPAN></SPAN>
mppApp.DisplayAlerts = False</SPAN></SPAN>
Application.EnableEvents = True</SPAN></SPAN>
'--------------------------- WAIT FOR IE TO CATCH UP --------------------------</SPAN></SPAN>
newHour = Hour(Now())</SPAN></SPAN>
newMinute = Minute(Now())</SPAN></SPAN>
newSecond = Second(Now()) + 3</SPAN></SPAN>
waitTime = TimeSerial(newHour, newMinute, newSecond)</SPAN></SPAN>
Application.Wait waitTime</SPAN></SPAN>
'------------------------------------------------------------------------------</SPAN></SPAN>
Set aProg = mppApp.ActiveProject</SPAN></SPAN>
'aProg.Visible = True</SPAN></SPAN>
Application.SendKeys "{TAB}" 'Enter to OK</SPAN></SPAN>
Application.SendKeys "^~" 'Enter yes to OK</SPAN></SPAN>
'COPY DATA ACROSS code</SPAN></SPAN>
Set mpApp = Nothing</SPAN></SPAN>
DoEvents</SPAN></SPAN>
MsgBox "Data from MS Project File Copied", vbInformation</SPAN></SPAN>
End Sub