06. juli 2005 - 13:19
Der er
1 kommentar og
1 løsning
KOpier FIler og Kør program?
Jeg har et lille program der henter nogen filer fra en anden computer, "Installer" dem et valgt sted. Og derefter skal den køre en af filerne som den lige har hentet!
MEN, den skal først starte EFTER at alle filerne er kopieret! Hvordan får jeg den til det??
Jeg bruger denne kode her:
---------------
Dim sti As String
Dim ExcelApp As Excel.Application
sti = "xcopy /E DATA C:\MCAU\DATA\"
Shell sti, vbHitResultClose
On Error Resume Next
Set ExcelApp = Excel.Application
ExcelApp.Workbooks.Open ("C:\MCAU\Data\Projektmapper\MCAU-menu EJMA 8-1-5.xls")
ExcelApp.Visible = True
End
--------------------
'---------------------------------- Form1 ----------------------------------
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const SYNCHRONIZE As Long = &H100000
Private Sub ShellAndWait(strFile As String, Optional intStyle As VbAppWinStyle = vbNormalFocus)
Dim hShell As Long
Dim hProcess As Long
Dim hSuccess As Long
hShell = Shell(strFile, intStyle)
hProcess = OpenProcess(SYNCHRONIZE, 0, hShell)
If hProcess <> 0 Then
Do
hSuccess = WaitForSingleObject(hProcess, 0&)
If hSuccess = 0 Then
CloseHandle hProcess
Exit Do
Else
DoEvents
Call Sleep(100)
End If
Loop
End If
End Sub
Private Sub Command1_Click()
Dim sti As String
Dim ExcelApp As Excel.Application
sti = "xcopy /E DATA C:\MCAU\DATA\"
ShellAndWait sti, vbHide ' <- ShellAndWait
Set ExcelApp = Excel.Application
ExcelApp.Workbooks.Open ("C:\MCAU\Data\Projektmapper\MCAU-menu EJMA 8-1-5.xls")
ExcelApp.Visible = True
End Sub
'---------------------------------- Form1 ----------------------------------