Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem to copy file

Posted on 2016-07-15
7
54 Views
Last Modified: 2016-07-17
Hi,
I get
5c.pngdue to this line
        FileSystemObject.CopyFile Source, Dest

while Source is having value
\\hkgmoss\sites\a4\IT\Projects\ExcelTool\BudgetExcelTool\CHINA\AsiaPacific_Budget_HO_2016-May.xlsm

Dest is
\\hkgmoss\sites\a4\IT\Projects\ExcelTool\BudgetExcelTool\CHINA\AsiaPacific_Budget_HO_CHINA_2016-Jun.xlsm
0
Comment
Question by:HuaMinChen
  • 3
  • 3
7 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
ID: 41711859
Have you defined and instantiated the FileSystemObject object? It would be a good idea to name such as object with a different name from the class name:
Dim fso  as  New FileSystemObject

'...
fso.CopyFile Source, Dest
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 41711861
Sorry missed using a snippet box:
Dim fso  as  New FileSystemObject 

'...
fso.CopyFile Source, Dest

Open in new window

0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41711867
I still get error due to these
        Dim fso  As New FileSystemObject
        fso.CopyFile Source, Dest
        

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
ID: 41711875
>>Dim fso  As New FileSystemObject
try check in References to see if there's any missing libraries?

alternatively, try this instead:
Dim fso As Object
fso = CreateObject("Scripting.FileSystemObject")
'...

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 41711906
If the error is

Compile error:
User-defined type not defined

then Ryan Chong's advice should work

Whenever you want to ask about an error, please tell us what the error message is.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41716214
I get
5f.pngdue to last line below
        Source = Replace(Replace(Source, "\", "/"), "//", "http://"): Dest = Replace(Replace(Dest, "\", "/"), "//", "http://")
        
        Dim fso As Object
        'Set fso = VBA.CreateObject("Scripting.FileSystemObject")
        Set fso = CreateObject("Scripting.FileSystemObject")
        'Dim fso  As New FileSystemObject
        fso.CopyFile Source, Dest

Open in new window

and Source is having value

http://hkgmoss/sites/a4/IT/Projects/ExcelTool/BudgetExcelTool/CHINA/AsiaPacific_Budget_HO_2016-May.xlsm

Open in new window

while Dest is
http://hkgmoss/sites/a4/IT/Projects/ExcelTool/BudgetExcelTool/CHINA/AsiaPacific_Budget_HO_CHINA_2016-Jun.xlsm

Open in new window

I still get the same problem even if I did not do replace on 1st line in above.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41716216
Please leave my last reply in above
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question