locked
Copy folders-Run time error '91' RRS feed

  • Question

  • Hi everyone.............

    The following is the code i tried for copying folders and file from the source path to the destination path.

    But I got an error message saying

    "run time error'91'
    Object variable or with block variable not set"

    So my idea is If i specify the path of the source and destination file in the text boxes in a user form, then If I click [copy] button it has to copy files and folders from the source path to the destination path.

    Can you help me with this plz............

    Here is my code

    Sub veeru()

    Dim source As Object
    Dim destination As Object
    source = UserForm1.TextBox1.Value
    destination = UserForm1.TextBox2.Value
    Set Fobj = CreateObject("Scripting.FileSystemObject")

    Fobj.CopyFolder "source", "destination"
    End Sub



    Veeru

    Monday, April 23, 2012 6:10 AM

Answers

  • Firstly do not declare the Soucre,desticnation as object.If still problem not solves then let us know what is string assigned to Source and destination.

    Dim source As String,destination As String
    source = UserForm1.TextBox1.Value
    destination = UserForm1.TextBox2.Value
    Set Fobj = CreateObject("Scripting.FileSystemObject")

    Fobj.CopyFolder source, destination
    End Sub

    • Proposed as answer by danishani Friday, April 27, 2012 5:54 AM
    • Marked as answer by danishani Thursday, September 11, 2014 6:09 PM
    Monday, April 23, 2012 8:14 AM
    Answerer

All replies

  • Do not use quotes.It forces to treat it as Literal string.

    Sub veeru()

    Dim source As Object
    Dim destination As Object
    source = UserForm1.TextBox1.Value
    destination = UserForm1.TextBox2.Value
    Set Fobj = CreateObject("Scripting.FileSystemObject")

    Fobj.CopyFolder source, destination
    End Sub

    Monday, April 23, 2012 6:42 AM
    Answerer
  • I removed the double quotes but still I am getting the same error message......

    Can you get me out of this,,,,,,,,,,,,,,


    Veeru

    Monday, April 23, 2012 7:33 AM
  • Firstly do not declare the Soucre,desticnation as object.If still problem not solves then let us know what is string assigned to Source and destination.

    Dim source As String,destination As String
    source = UserForm1.TextBox1.Value
    destination = UserForm1.TextBox2.Value
    Set Fobj = CreateObject("Scripting.FileSystemObject")

    Fobj.CopyFolder source, destination
    End Sub

    • Proposed as answer by danishani Friday, April 27, 2012 5:54 AM
    • Marked as answer by danishani Thursday, September 11, 2014 6:09 PM
    Monday, April 23, 2012 8:14 AM
    Answerer