We help IT Professionals succeed at work.

Problem to execute command

77 Views
Last Modified: 2016-03-31
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.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT

Commented:
Peter ChanProblem resolver

Author

Commented:
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?
Peter ChanProblem resolver

Author

Commented:
In my case. Many thanks
Peter ChanProblem resolver

Author

Commented:
Any other help?
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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.
Peter ChanProblem resolver

Author

Commented:
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
x.png
if I issue the same, within VBA codes, using "Shell" to run the command. Why?
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Please show the corresponding lines (Shell call and used variables, if any).
Peter ChanProblem resolver

Author

Commented:
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

"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.