Results 1 to 3 of 3

Thread: FileSystem.CopyFile not working on Shared Drive

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    11

    FileSystem.CopyFile not working on Shared Drive

    Hello,

    I am populating a spread sheet, via VS2010, which is stored on a shared drive.
    Then it automatically create a separate folder with the name of that file, e.g. file "A.23.04.2018"

    The problem comes when I try to copy the workbook from the shared drive onto its dedicated folder.

    It doesn't even throw an error, just creates the folder which is always empty.

    Code:
    Private Sub CreateFolder()
            Dim xlSheet As Object = CType(xlApp.Worksheets("Form"), Excel.Worksheet)
            Dim YourPath As String = IO.Path.Combine("\\frtstpr-dna203a\tou5\Example_Design\11_SSBD\01_SSBD_Lcl_ad_open\Improvements\" + xlSheet.cells(6, 2).value.ToString + xlSheet.cells(6, 3).value.ToString + xlSheet.cells(6, 4).value.ToString)
    
            Try
                If (Not System.IO.Directory.Exists(YourPath)) Then
                    System.IO.Directory.CreateDirectory(YourPath)
                End If
                My.Computer.FileSystem.CopyFile( _
        "\\frtstpr-dna203a\tou5\Example_Design\01_SSBD\01_SSBD_Lcl_ad_open\Improvements\TR tracker\TR_Template_Draft_01.xlsm", _
        YourPath & ".xlsm", overwrite:=False)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub
    Any help would be appreciated.

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: FileSystem.CopyFile not working on Shared Drive

    Code:
    Private Sub CreateFolder()
            Dim xlSheet As Object = CType(xlApp.Worksheets("Form"), Excel.Worksheet)
            Dim YourPath As String = IO.Path.Combine("\\frtstpr-dna203a\tou5\Example_Design\11_SSBD\01_SSBD_Lcl_ad_open\Improvements\" + xlSheet.cells(6, 2).value.ToString + xlSheet.cells(6, 3).value.ToString + xlSheet.cells(6, 4).value.ToString)
    
            Try
                If (Not System.IO.Directory.Exists(YourPath)) Then
                    System.IO.Directory.CreateDirectory(YourPath)
                End If
    messagebox.show(YourPath & ".xlsm") '<--- new! what is the path that is shown? maybe not what you expect? post the result.
                My.Computer.FileSystem.CopyFile( _
        "\\frtstpr-dna203a\tou5\Example_Design\01_SSBD\01_SSBD_Lcl_ad_open\Improvements\TR tracker\TR_Template_Draft_01.xlsm", _
        YourPath & ".xlsm", overwrite:=False)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    11

    Re: FileSystem.CopyFile not working on Shared Drive

    Quote Originally Posted by digitalShaman View Post
    Code:
    Private Sub CreateFolder()
            Dim xlSheet As Object = CType(xlApp.Worksheets("Form"), Excel.Worksheet)
            Dim YourPath As String = IO.Path.Combine("\\frtstpr-dna203a\tou5\Example_Design\11_SSBD\01_SSBD_Lcl_ad_open\Improvements\" + xlSheet.cells(6, 2).value.ToString + xlSheet.cells(6, 3).value.ToString + xlSheet.cells(6, 4).value.ToString)
    
            Try
                If (Not System.IO.Directory.Exists(YourPath)) Then
                    System.IO.Directory.CreateDirectory(YourPath)
                End If
    messagebox.show(YourPath & ".xlsm") '<--- new! what is the path that is shown? maybe not what you expect? post the result.
                My.Computer.FileSystem.CopyFile( _
        "\\frtstpr-dna203a\tou5\Example_Design\01_SSBD\01_SSBD_Lcl_ad_open\Improvements\TR tracker\TR_Template_Draft_01.xlsm", _
        YourPath & ".xlsm", overwrite:=False)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub

    That msgox you suggested clarified things, I just had to edit my path.

    Thanks DigitalShaman!

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width