473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

FileCopy command - run time error 52 in Excel VBA

I'm trying to copy a file from a SharePoint location to a network folder. I can get the file to Open and save as but all I really need to do is copy it.

Code looks like this:
Expand|Select|Wrap|Line Numbers
  1. strPathSrc = "SharepointLoc/My%20Reports/"
  2. strPathTgt = "P:\MyReports\"
  3.  
  4. strFileSrc = "This%20File.xlsx"
  5. strFileTgt = "This File.xlsx"
  6.  
  7. Filecopy strPathSrc & strFileSrc, strPathTgt & strFileTgt
On run, I'm getting the error 52 but again, if I run the code below, I'm good, so I think that the paths and file names are ok.

Expand|Select|Wrap|Line Numbers
  1. Workbooks.Open Filename:=strSrcFull
  2.  
  3. Workbooks(strFileTgt).SaveAs strTgtFull
  4.  
  5. Workbooks(strFileTgt).Close
Any help would be so appreciated!
Aug 21 '18 #1
13 4526
Rabbit
12,516 Expert Mod 8TB
Opening a file from within Excel uses a different mechanism than using the file system to copy a file. While Excel knows how to connect to SharePoint, the file system itself does not.
Aug 21 '18 #2
Ahhh... so I'm not going to be able to use the Filecopy command here and will have to open and save as instead. Thank you!
Aug 21 '18 #3
zmbd
5,501 Expert Mod 4TB
Last year I had a very similar problem
I ran across this in another forum.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'Thank you Tragamor for the following code:
  5.  
  6. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
  7.     ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
  8.  
  9. Function DownloadFileFromWeb(strURL As String, strSavePath As String) As Long
  10.     ' strSavePath includes filename
  11.     DownloadFileFromWeb = URLDownloadToFile(0, strURL, strSavePath, 0, 0)
  12. End Function 
the "strSavePath" is the fully qualified file-path and file-name you are saving the document to; thus, if your network drive is mapped to "Z:" then you might have something like:
strSavePath = "Z:\directory\YourNewFileName.xtn"

Expand|Select|Wrap|Line Numbers
  1. (...)
  2.  strPathSrc = "SharepointLoc/My%20Reports/"
  3.  strPathTgt = "P:\MyReports\"
  4.  
  5.  strFileSrc = "This%20File.xlsx"
  6.  strFileTgt = "This File.xlsx"
  7.  
  8.  strFullSrc = strPathSrc & stFileSrc
  9.  strFullTgt = strPathTgt & strFileTgt 
  10.  
  11.  lngSuccess = DownloadFileFromWeb(strFullSrc, strFullTgt )
  12. (...)
function returns a zero if there are no errors

BTW: Although Allowed with the newer OS, IMHO, file names should only contain alphanumeric and the underscore, no spaces nor special characters.
Smithsonian Data Management Best Practices
(While this suggests the hyphen, I personally avoid it too as it can be interpreted as a negative or subtraction function)
Aug 21 '18 #4
twinnyfo
3,653 Expert Mod 2GB
All y'all,

Do all y'all realize that the web address for SharePoint is different than the File Structure address for SharePoint?

If I try to save something to my SharePoint web address: "https://SharePoint.Web.Address/org/A1/A1K/A1KM/A1KMP/", I will get an error.

However, if I try to save a file to my SharePoint File Structure address: "\\SharePoint.Web.Address@SSL\DavWWWRoot\org\A1\A1 K\A1KM\A1KMP\", I am able to connect. You can even add this address to your Windows File Manager as a Shortcut.

The only restriction is that you must connect to that location and make sure your file system can find that folder before you can automate it through VBA.

I use this method all the time without hitch or stitch.

Hope this hepps!
Aug 22 '18 #5
NeoPa
32,556 Expert Mod 16PB
TwinnyFo:
You can even add this address to your Windows File Manager as a Shortcut.
I assume you mean "... as a drive letter."?

Very helpful info Twinny :-)
Aug 22 '18 #6
twinnyfo
3,653 Expert Mod 2GB
Yes, you could assign it a drive letter, but I prefer not to and use the location explicitly in any VBA, just in case others might assign different drive letters. I can also drag folders into my Quick Access list.

Incredibly convenient once I learned how to do it.
Aug 22 '18 #7
NeoPa
32,556 Expert Mod 16PB
I wasn't suggesting an alternative option my friend. I was translating your comment so that it made sense to me. I otherwise have no understanding of what you mean by "You can even add this address to your Windows File Manager as a Shortcut.".

As you comment, I also prefer to use UNC notation when referring to network addresses from within software. It's more robust.
Aug 23 '18 #8
twinnyfo
3,653 Expert Mod 2GB
No offense taken, my friend--I was just not describing a drive letter. Since MS keeps changing what everthing is called, I sometimes confuse myself.

Hence, I still cling to the old moniker "File Manager" which sometimes slips out of my fingertips when what I really mean is "Windows Explorer".

And "shortcut" slips out, because it is easier to say and remember than "Quick Access List".

So, your confusion is justified and understandable.

Next week MS plans on renaming "Windows Explorer" to the "File Operations and Organization Listing Integrating the System Host" (FOOLISH). And the "Quick Access List" will be renamed "Method for Easily Adding Temporary Hotlinks Everyone can Access Directly" (MEATHEAD).

I'm sure you would agree that this would be a great improvement!
Aug 23 '18 #9
NeoPa
32,556 Expert Mod 16PB
I'm not sure I even understand what a "Quick Access List" is in Windows Explorer, but I can see you weren't trying to say "Drive" so I'll leave it at that ;-)

I think we both agree a drive wouldn't be the best way to do it in software, but beyond that we have no real need to go :-)

PS. Nice acronyms :-D
Aug 23 '18 #10
twinnyfo
3,653 Expert Mod 2GB
Ahhh.....

So, let me show you (top left):

Attached Images
File Type: jpg QuickAccess.jpg (66.1 KB, 1718 views)
Aug 23 '18 #11
NeoPa
32,556 Expert Mod 16PB
Ahhh (Right back atcha!)
On my Windows 7 system that would be equivalent to Favourites I suspect (although spelt wrong of course ;-)).
Aug 23 '18 #12
zmbd
5,501 Expert Mod 4TB
NeoPa - Tisk Tisk :)
Yes it's the favorites list - or you can add the link into the Libraries directory.

TwinneyFo,
At my work, the UNC link to the sharepoint server is apparently blocked either by group-policy or by the active directory server; however, the method I gave earlier works.
Aug 23 '18 #13
twinnyfo
3,653 Expert Mod 2GB
Z - Ain’t it grand how there are so many ways to skin the same cat that something is bound to work sooner or later. Thanks for giving me an alternate method for when they lock down our servers even more!
Aug 23 '18 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
0
by: Robert McGregor | last post by:
Using the follwing code and getting the error message: Run time error '2455': You entered an expression that contains an invalid reference to the property MaxRecButton. My code just...
2
by: dailem | last post by:
I have a bit of code tied to a command button in Access that runs a query then transfers it to a new Excel worksheet (& new file). It works fine EVERY OTHER TIME THAT I RUN IT....what the 'heck...
0
by: Newcomer | last post by:
Hi everybody, For sure an easy thing for you to solve. But for me as non expert I cannot find the mistake. I wrote an easy find command as shown here Range("A:A").Select
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
7
by: TracyWants2Know | last post by:
Access Version: 2002 SP3 OS: MS Windows XP Professional Code from Module: Dim txtFileNameBuES As String Dim txtFileNameBuESXP As String Dim txtPathNameBuTo As String ...
1
by: zedd | last post by:
Hi, I orignaly posted this with the error above, however I am still trying to solve it on my own, and found that some of my syntax in the query was not correct and I corrected it. But i am still...
5
by: titli | last post by:
Hi guys, I have a .mdb which generates , further some mini .mdbs..Later these generated mini mdbs are provided as input to excel viewer.Till yesterday everything was working fine.. But today after...
0
by: strpradeep | last post by:
hello everyone.. i am new to vb6 and i am developing a small application using excel to create an instance of excel. the following code gives me the run time error. please help me.. Private Sub...
0
by: Art Altman | last post by:
I have found a workaround to the Excel VBA “ run time error 40036 application-defined or object error”. It does not fix the original problem, which is in excel, SOMEWHERE. A few responses I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.