Results 1 to 6 of 6

How do i insert a cloud pathway like sharepoint/teams folder in my macro to save documents

Threaded View

  1. #1
    Registered User
    Join Date
    06-13-2023
    Location
    London
    MS-Off Ver
    365
    Posts
    18

    How do i insert a cloud pathway like sharepoint/teams folder in my macro to save documents

    Hi all,

    im getting an error when i try to use a cloud folder location as my place to save images in, i can successfully use a local folder on my dektop but it fails when i try to use a url location

    im sure im doing soemthing wrong

    "X:\WFS\Reporting\Sukh\202401" & newFileName & ".jpg"

    thats the local folder but i want it to be a sharepoint folder url like

    https://its007149.sharepoint.com/sit...471201286E86E2



    thNewNameAndDisplayPath()
        ' Get the last used row in column AM
        Dim lastRow As Long
        lastRow = Cells(Rows.Count, "AM").End(xlUp).Row
        
        ' Loop through each row in column AM
        Dim i As Long
        For i = 4 To lastRow ' Assuming data starts from row 4
            ' Get the image file path from the current row in column AM
            Dim imagePath As String
            imagePath = Trim(Cells(i, "AM").Value)
            
            ' Get the new file name from the current row in column AL
            Dim newFileName As String
            newFileName = Cells(i, "AL").Value
            
            ' Check if the image file path is not empty
            If Len(imagePath) > 0 Then
                ' Check if the file exists using FileSystemObject
                Dim fs As Object
                Set fs = CreateObject("Scripting.FileSystemObject")
                
                If fs.fileExists(imagePath) Then
                    ' Build the new file path with the specified name
                    Dim newFilePath As String
                    newFilePath = "X:\WFS\Reporting\Sukh\202401" & newFileName & ".jpg" ' Change the path as needed
                    
                    ' Use FileSystemObject for file operations
                    Dim fs2 As Object
                    Set fs2 = CreateObject("Scripting.FileSystemObject")
                    
                    ' Check if the destination folder exists; if not, create it
                    If Not fs2.FolderExists("X:\WFS\Reporting\Sukh\202401") Then
                        fs2.CreateFolder "X:\WFS\Reporting\Sukh\202401"
                    End If
                    
                    ' Copy the image to the new file path
                    fs2.CopyFile imagePath, newFilePath, True
                    
                    ' Display the new file path as a hyperlink in the corresponding row in column AN
                    Cells(i, "AN").Formula = "=HYPERLINK(""" & newFilePath & """)"
                Else
                    MsgBox "Error: The specified image file does not exist in row " & i & ".", vbExclamation
                End If
            Else
                MsgBox "Error: Please provide a valid image file path in row " & i & ".", vbExclamation
            End If
        Next i
        
        ' Inform the user about the success outside the loop
        MsgBox "Images saved successfully.", vbInformation
    End Sub"


    Appreciate any help on this matter

    Many thanks
    Last edited by AliGW; 01-23-2024 at 08:37 AM. Reason: Code tags corrected.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Save Individual Tabs into new Subfolder on Sharepoint folder
    By Chuckf1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2022, 10:44 AM
  2. [SOLVED] How to shorten up folder pathway with this workbook.path
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2018, 07:35 PM
  3. Save as pdf in current folder in Sharepoint
    By Jacc in forum Word Programming / VBA / Macros
    Replies: 5
    Last Post: 12-22-2015, 08:25 PM
  4. VBA to save file to sharepoint folder
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-20-2014, 04:56 PM
  5. [SOLVED] pathway reference to file givs out of range errormsg (pathway is set as variable)
    By phila7475 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 04:51 AM
  6. Macro to open a folder containing documents
    By jrdunn78hawk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-06-2012, 09:52 AM
  7. [closed - opening new thread] Save xlsm to Sharepoint/Web Folder
    By phi11yguy19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-03-2011, 08:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1