Consulting

Results 1 to 3 of 3

Thread: Solved: CopyFolder into Dynamic Parent Directory

  1. #1

    Solved: CopyFolder into Dynamic Parent Directory

    I have the following code which is only part of a whole routine. What I'm tyring to do is prompt the user to enter a name for a new directory that I am going to create and then copy two subdirectories into. I have included only one subdirectory since they are just about identical. My problem is that when I try to CopyFolder into the newly created directory, I get the compile error that a constant expression is required. Please help, it's driving me bonkers.
    Thanks!
    [VBA]
    Sub total()
    Call NetDirectory
    Call CopyFileNetworkWO

    End Sub

    Sub NetDirectory()
    Dim HistoryDir As String

    '****Asks the user to input the Dir name, then creates Dir
    Load UserForm3
    UserForm3.Show
    HistoryDir = UserForm3.TextBox1.Value
    MkDir "K:\History\2006\" & HistoryDir
    End Sub

    Sub CopyFileNetworkWO()
    Dim HistoryDir As String
    HistoryDir = UserForm3.TextBox1.Value

    '****This is copying the files from C:\WithoutCost to J:\WithoutCost
    Const DirFromM As String = "c:\withoutcost"
    Const DirToM As String = "K:\History\2006\" & HistoryDir & "\" 'This is the problem
    Dim fso As FileSystemObject
    Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FilesystemObject")

    oFSO.CopyFolder DirFromM, DirToM

    End Sub[/VBA]

  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Sherry,

    Your problem is that your constant is not really a constant--it's a variable, because it's definition relies on HistoryDir, which is itself a variable.

    Declare DirToM as a variable, and you should be OK.

    Patrick

  3. #3
    Duh! Thank you very much. It works great!

Posting Permissions

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