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: - strPathSrc = "SharepointLoc/My%20Reports/"
-
strPathTgt = "P:\MyReports\"
-
-
strFileSrc = "This%20File.xlsx"
-
strFileTgt = "This File.xlsx"
-
-
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. - Workbooks.Open Filename:=strSrcFull
-
-
Workbooks(strFileTgt).SaveAs strTgtFull
-
-
Workbooks(strFileTgt).Close
Any help would be so appreciated!
13 4526
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.
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!
zmbd 5,501
Expert Mod 4TB
Last year I had a very similar problem
I ran across this in another forum. - Option Compare Database
-
Option Explicit
-
-
'Thank you Tragamor for the following code:
-
-
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
-
ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
-
-
Function DownloadFileFromWeb(strURL As String, strSavePath As String) As Long
-
' strSavePath includes filename
-
DownloadFileFromWeb = URLDownloadToFile(0, strURL, strSavePath, 0, 0)
-
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" - (...)
-
strPathSrc = "SharepointLoc/My%20Reports/"
-
strPathTgt = "P:\MyReports\"
-
-
strFileSrc = "This%20File.xlsx"
-
strFileTgt = "This File.xlsx"
-
-
strFullSrc = strPathSrc & stFileSrc
-
strFullTgt = strPathTgt & strFileTgt
-
-
lngSuccess = DownloadFileFromWeb(strFullSrc, strFullTgt )
-
(...)
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)
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!
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 :-)
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.
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.
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!
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
Ahhh.....
So, let me show you (top left): 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 ;-)).
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.
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |