Link to home
Start Free TrialLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Problem to execute command

Hi,
Within Excel, I am able to directly open the file, by putting this

\\hkgmoss\sites\a4\IT\A4 Projects\Excel Tool\Budget Excel Tool\China-Cnsnh\.\Feb0.xlsm

Open in new window


But I get
The system cannot find the file specified.

Open in new window


if I issue
copy \\hkgmoss\sites\a4\IT\A4 Projects\Excel Tool\Budget Excel Tool\China-Cnsnh\.\Feb0.xlsm \\hkgmoss\sites\a4\IT\A4 Projects\Excel Tool\Budget Excel Tool\China-Cnsnh\..\China\AsiaPacific_Budget_HO China_2016-Feb.xlsm

Open in new window

on Windows prompt. And I do expect further such command by a Shell command within VBA.
Avatar of Farzad Akbarnejad
Farzad Akbarnejad
Flag of Iran, Islamic Republic of image

Hi,
Copy command needs to specify source and destination:
try:

copy   file  destfilespec

you must specify path of destination to copy on it with source file name

-FA
Avatar of Peter Chan

ASKER

Sorry, it says the OS cannot find out the file but I can open that file in Excel using the same path and file name.

What to adjust to the copy command?
In my case. Many thanks
Any other help?
You need to enclose the path and filename in double quotes, because of the spaces. Spaces separate parameters, and so the copy thinks you have more than two parameters provided, and each is incomplete.
copy "\\hkgmoss\sites\a4\IT\A4 Projects\Excel Tool\Budget Excel Tool\China-Cnsnh\.\Feb0.xlsm" "\\hkgmoss\sites\a4\IT\A4 Projects\Excel Tool\Budget Excel Tool\China-Cnsnh\..\China\AsiaPacific_Budget_HO China_2016-Feb.xlsm"

Open in new window

You can enclose the path in all cases, it never hurts.
Hi,
I am able to run
copy "\\hkgmoss\sites\a4\IT\Projects\ExcelTool\BudgetExcelTool\China-Cnsnh\.\Feb0.xlsm" "\\hkgmoss\sites\a4\IT\Projects\ExcelTool\BudgetExcelTool\China-Cnsnh\..\China\AsiaPacific_Budget_HO China_2016-Feb.xlsm"/y

on Windows prompt, but I have got "File not found" problem like
User generated image
if I issue the same, within VBA codes, using "Shell" to run the command. Why?
Please show the corresponding lines (Shell call and used variables, if any).
The last line below, is leading to the error. Thanks.
    If Dir(File0) = "" Then
        If InStr(SiteName, "-") > 0 Then
        Dim Command0 As String
        Command0 = "copy """ & Path0 & "\.\" & Current_Book & """ """ & Path0 & "\..\China\" & Window0 & """/y"
        
        Shell (Command0)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial