Display copy progress with the copy command

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Display copy progress with the copy command

Post by mydave » Fri Jul 22, 2005 12:46 pm

Hi,
The copy function works great.
But for copying a large file, I wish that there is a way to pop up the usual window copying progress so user know something is going on.
Could this be done?
Thanks

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Jul 25, 2005 5:27 pm

Hi,

You can do this with the shell.application object in VBScript:

VBSTART
Const FOF_ALLOWUNDO = 64
Const FOF_CONFIRMMOUSE = 2
Const FOF_COPYFLAGS = 989
Const FOF_DELETEFLAGS = 340
Const FOF_FILESONLY = 128
Const FOF_MOVEFLAGS = 989
Const FOF_MULTIDESTFILES = 1
Const FOF_NOCONFIRMATION = 16
Const FOF_NOCONFIRMMKDIR = 512
Const FOF_RENAMEFLAGS = 989
Const FOF_RENAMEONCOLLISION = 8
Const FOF_SILENT = 4
Const FOF_SIMPLEPROGRESS = 256
Const FOF_WANTMAPPINGHANDLE = 32

Sub CopyProgress(destfolder,sourcefile)
set winShell = createObject("shell.application")
winShell.namespace(destfolder).CopyHere sourcefile, FOF_SIMPLEPROGRESS
End Sub
VBEND
VBRun>CopyProgress,f:\,d:\test\test.txt
MJT Net Support
[email protected]

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Thu Aug 04, 2005 12:16 pm

Thanks greatly for the help.
I tried with a replacements for the 'desfolder' and 'sourcefile' in the two statements:
Sub CopyProgress(destfolder,sourcefile)
. . . . .
winShell.namespace(destfolder) . . . . .
and some other changes, but could not get it to work.
Most cases, I got error message " MS VBScript compilation error:1006, Expect ')', Line xx, column xx."

I would much appreciate a little more help as to how to use it.
Thanks greatly

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Aug 04, 2005 12:43 pm

Line xx, Column xx or did it actually give a proper line and column number? Then we can know where the problem is.
MJT Net Support
[email protected]

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Thu Aug 04, 2005 9:00 pm

Hi Support,
Yes, the error is "MS VBScript compilation error: 1006. Expect ')', Line 16, Column 18".

And here is the test script:
(line 16 seems to be the "Sub CopyProgress(C:\downloads\,C:\TempDVD\Myfile.iso).
Thanks

VBSTART
Const FOF_ALLOWUNDO = 64
Const FOF_CONFIRMMOUSE = 2
Const FOF_COPYFLAGS = 989
Const FOF_DELETEFLAGS = 340
Const FOF_FILESONLY = 128
Const FOF_MOVEFLAGS = 989
Const FOF_MULTIDESTFILES = 1
Const FOF_NOCONFIRMATION = 16
Const FOF_NOCONFIRMMKDIR = 512
Const FOF_RENAMEFLAGS = 989
Const FOF_RENAMEONCOLLISION = 8
Const FOF_SILENT = 4
Const FOF_SIMPLEPROGRESS = 256
Const FOF_WANTMAPPINGHANDLE = 32
Sub CopyProgress(C:\downloads\,C:\TempDVD\Myfile.iso)
set winShell = createObject("shell.application")
winShell.namespace(C:\downloads\).CopyHere sourcefile, FOF_SIMPLEPROGRESS
End Sub
VBEND
VBRun>CopyProgress,C:\temp\,d:\test\test.txt

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Aug 04, 2005 9:21 pm

Hi,

The subroutine definition should not have literals in it. These should be parameters. Your code should look like this:

VBSTART
Const FOF_ALLOWUNDO = 64
Const FOF_CONFIRMMOUSE = 2
Const FOF_COPYFLAGS = 989
Const FOF_DELETEFLAGS = 340
Const FOF_FILESONLY = 128
Const FOF_MOVEFLAGS = 989
Const FOF_MULTIDESTFILES = 1
Const FOF_NOCONFIRMATION = 16
Const FOF_NOCONFIRMMKDIR = 512
Const FOF_RENAMEFLAGS = 989
Const FOF_RENAMEONCOLLISION = 8
Const FOF_SILENT = 4
Const FOF_SIMPLEPROGRESS = 256
Const FOF_WANTMAPPINGHANDLE = 32

Sub CopyProgress(destfolder,sourcefile)
set winShell = createObject("shell.application")
winShell.namespace(destfolder).CopyHere sourcefile, FOF_SIMPLEPROGRESS
End Sub

VBEND
VBRun>CopyProgress,C:\downloads\,C:\TempDVD\Myfile.iso

It is the VBRun line you should put the literals into and these are passed into the subroutine via the destfolder and sourcefile parameters which are declared in the subroutine declaration and used in the subroutine.
MJT Net Support
[email protected]

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Fri Aug 05, 2005 12:29 am

Yes it works perfectly.
Thank you support.

jennylci
Newbie
Posts: 14
Joined: Wed May 08, 2013 11:16 pm

Post by jennylci » Fri May 17, 2013 12:21 am

Hi Support,

I have the same question as mydave. The subroutine and functions are created by some one else and used before. So they shouldn't have any problem. But when I try to use it as VBEval>SetCell("B_Operations",%cc%,8,%TS1%),nul it doesn't work. And give me the same error message "Error 1006 Expected ")"". Could you take a look and tell me what's wrong with my code? Thank you very much.

Code: Select all

VBSTART
Dim xlApp
Dim xlBook
'Opens the Excel file in Excel
Sub OpenExcelFile(filename)
  Set xlApp = CreateObject("Excel.Application")
  xlApp.visible = false
  Set xlBook = xlApp.Workbooks.open(filename)
end sub

'Use this to close Excel later
Sub CloseExcel
   xlBook.Save
   xlApp.quit
   Set xlApp = Nothing
End Sub

'Retrieves a cell value from the specified
'worksheet
Function GetCell(Sheet,Row,Column)
  Dim xlSheet
  Set xlSheet = xlBook.Worksheets(Sheet)
  GetCell = xlSheet.Cells(Row,Column).Value
End Function

'Sets specified cell of specified worksheet
Function SetCell(Sheet,Row,Column,NewValue)
  Dim xlSheet
  Set xlSheet = xlBook.Worksheets(Sheet)
  xlSheet.Cells(Row,Column).Value = NewValue
End Function
VBEND

VBRun>OpenExcelFile,B:\PRODUCTION\MASTER_AUDIT\ScoreCard\Score_Card_Template.xls
DayOfWeek>days
GetDate>date
let>c=6
let>r=8
If>days>2
FileTime>B:\T_Folder\T_Confirm_%YYYY%%MM%%DD%.txt,time1
MidStr>time1,1,2,Hour1
MidStr>time1,3,2,Min1
Let>TS1=%date%%SPACE%%Hour1%:%Min1%
Let>cc=c+%days%
VBEval>SetCell("B_Operations",%cc%,8,%TS1%),nul
endIf
VBRun>CloseExcel
[/code]

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri May 17, 2013 8:59 am

TS1 is the new value which is a string, so you need:

VBEval>SetCell("B_Operations",%cc%,8,"%TS1%"),nul
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jennylci
Newbie
Posts: 14
Joined: Wed May 08, 2013 11:16 pm

Post by jennylci » Sat May 18, 2013 12:23 am

Thank you very much Marcus, it works perfectly!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts