small vb code not working correctly

Associate
Joined
26 Feb 2004
Posts
971
Location
China (Qinhuangdao)
I wrote this simple code to backup an Excel spreadsheet, before opening it. Every time I launch the program, it backs up my spreadsheet, and opens it correctly, but it doesn't terminate itself, so I see it's still present in task manager, and I have to end it manually.

Can anyone help me as to why my code won't self-terminate?


Sub Main()

Dim SourceFolder, DestFolder As String
Dim SourceFName, DestFName As String
Dim TimeDateStamp As String

SourceFolder = "E:\Current Interest\Financial\"
DestFolder = "E:\Current Interest\Financial\Backups of Spending in China\"

SourceFName = "Spending in China.xls"

TimeDateStamp = Format(FileDateTime(SourceFolder & SourceFName), "yyyy") & "-" & Format(FileDateTime(SourceFolder & SourceFName), "mm") & _
"-" & Format(FileDateTime(SourceFolder & SourceFName), "dd")

DestFName = TimeDateStamp & " " & SourceFName

' Backup File
Set fs = CreateObject("Scripting.FileSystemObject")
fs.Copyfile SourceFolder & SourceFName, DestFolder & DestFName, True ' True means overwrite

' Launch the program
MyAppID = Shell("C:\Program Files\Microsoft Office\Office10\EXCEL.EXE ""E:\Current Interest\Financial\Spending in China.xls""", vbMaximizedFocus)
AppActivate MyAppID, True ' Activate Microsoft Excel, and 'Spending'

' Terminate this code
End

End Sub
 
That doesn't work, unfortunately.
I get the error message : 'Object doesn't support this property or method'.

I think I've cured it by changing the AppActivate command. I changed this to :

AppActivate MyAppID, False

This seems to finish the code before the Excel spreadsheet is open, and terminates successfully.
 
Back
Top Bottom