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.
VB ScriptVBAProgrammingMicrosoft ApplicationsWindows Batch

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
Farzad Akbarnejad

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
Farzad Akbarnejad

ASKER
Peter Chan

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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
Peter Chan

In my case. Many thanks
ASKER
Peter Chan

Any other help?
Qlemo

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Peter Chan

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

Please show the corresponding lines (Shell call and used variables, if any).
ASKER
Peter Chan

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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question