Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
nihhalmca
Specialist II

How to Upload excel files to SharePoint (URL) by Macro

Hi All,

How to Upload excel files to SharePoint (URL) by Macro.

Can you share the vb script plz.

Thanks,

Nihhal.

1 Solution

Accepted Solutions
nihhalmca
Specialist II
Author

Hi All, thanks for your help.

And I resolved issue by using UNC path instead of URL in macro code.

View solution in original post

9 Replies
martynlloyd
Partner - Creator III

Hi Nihhal

Use a normal save, you can get the UNC path by doing open in Explorer from the SharePoint library.

Kind regards,

Marty.

nihhalmca
Specialist II
Author

Hi Martyn,

I tried and i can able to upload this way however i do not have access to UNC path from server (some security resons).

I can able to access SharePoint by url itself from server.

Could you tell one thing, is it possible?

Not applicable

HI Nihhal,

as option you could use standard tools like OneDrive which has synchronization with SharePoint, but in case of using SP 365 nothing helps you except specially designed services.

sajalgour2309
Contributor II

Hello Nihhal,

I have a code which i used in excel vba to do this task, hope this will help.

Sub Copy_Jugal_Data()

    Dim FSO As Object

    Dim FromPath As String

    Dim ToPath As String

   

    On Error GoTo Jugal_Help

    FromPath = "give excel path"

    ToPath = "give share point path"

    If Right(FromPath, 1) = "\" Then

        FromPath = Left(FromPath, Len(FromPath) - 1)

    End If

    If Right(ToPath, 1) = "\" Then

        ToPath = Left(ToPath, Len(ToPath) - 1)

    End If

    Set FSO = CreateObject("scripting.filesystemobject")

    If FSO.FolderExists(FromPath) = False Then

        MsgBox FromPath & " Path doesn't exist"

        Exit Sub

    End If

    FSO.CopyFolder Source:=FromPath, Destination:=ToPath

   

MsgBox " Mr. Jugal you can find the files in " & ToPath

Jugal_Help:

Masgbox "Error"

End Sub

If you want to save any activeworkbook than you can use below code.

Sub Save_tosharepoint()

Dim FileName, FilePath As String

    Let FilePath = "give share point path"

    Let FileName = "give filename"

    ActiveWorkbook.SaveAs FileName:=thepath & thefile _

        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

End Sub

nihhalmca
Specialist II
Author

Hi Sajal - Thank you,

Its not working for me, i think its is VBA and i am looking for VBS.

Do you have VBS code or do you know how to convert from VBA to VBS.

martynlloyd
Partner - Creator III

Hello Nihhal,

To upload to URL, you would need to use SOAP, or other low-level SharePoint code.  Some 3rd party apps are out there, you could look at Bamboo Software for instance.

It seems unusual that you have write access to the SharePoint library, but not via Windows Explorer - have you tried a simple drag-and-drop into the folder, does that work?

Marty.

martynlloyd
Partner - Creator III

from Microsoft

Key Differences Between Visual Basic for Applications and VBScript

File Operations

VBScript does not support any of the file operations found in Visual Basic for Applications, such as reading and writing to a file. Once again, this is because of the risks involved in being able to access the client machine without restriction. Clearly, allowing direct file I/O from the browser places the client machine at the mercy of any rogue executable that gets downloaded.

Marty.

martynlloyd
Partner - Creator III

Hi Nihhal,

I checked several posts on Stack Overflow

I think it is not possible using VBS.

Regards,

Marty.

nihhalmca
Specialist II
Author

Hi All, thanks for your help.

And I resolved issue by using UNC path instead of URL in macro code.