A family of Microsoft word processing software products for creating web, email, and print documents.
Does this work?
Set mySubFolder = myFolders.Add(arrSubProj(I))
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have an array with (for example) the following values:
arrSubProj(1) = "AAA"
arrSubProj(2) = "BBB"
arrSubProj(3) = "CCC"
I want to use these as the names of folders, which I can later move to be subfolders of another folder - that is, ending with something like:
MyTopFolder
AAA
BBB
CCC
But when I try:
If optCommercial.Value = True And txtNumSubProj.Value > 0 Then
For I = 1 To txtNumSubProj.Value
Set mySubFolder = myFolders.Add(" & arrSubProj(I) & ")
Next I
I get a message that the folder already exists - and indeed the folder & arrSubProj(I) & is there - it's just not what I wanted.
How do I get it to use the values in the array in the Add, instead of the array name itself?
Help, please.
Many thanks!
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Does this work?
Set mySubFolder = myFolders.Add(arrSubProj(I))
If you add
Debug.Print myFolders.Add(arrSubProj(I))
below the the For I = 1 To txtNumSubProj.Value line, what do you see in the Immediate window?
Dim myFileSys As New FileSystemObject
Dim myBaseFolder As Folder
Dim mySubFolder As Folder
Dim myFolders As Folders
Dim strRootPath As String
Dim intIDYear As Integer
Dim I as integer
intIDYear = Right(cboIDYear.Value, 2)
txtBDNumber.Value = txtBDNumber.Value & cboProposalType.Value
strRootPath = "\syn01\Proposals\EGS" & cboIDYear.Value & ""
Set myBaseFolder = myFileSys.CreateFolder(strRootPath & "EGS" & intIDYear & txtBDNumber.Value & " " & txtClientName.Value & " " & txtClientProposalTitle.Value & "")
ChDir (myBaseFolder)
Set myFolders = myBaseFolder.SubFolders
Set mySubFolder = myFolders.Add("Kickoff")
Set mySubFolder = myFolders.Add("Introduction")
Set mySubFolder = myFolders.Add("Signed")
Set mySubFolder = myFolders.Add("Submitted")
Set mySubFolder = myFolders.Add("Postmortem")
Set mySubFolder = myFolders.Add("Site Survey")
etc. for several other named folders relevant to the projects we work on.
followed by
If optCommercial.Value = True And txtNumSubProj.Value > 0 Then
For I = 1 To txtNumSubProj.Value
Set mySubFolder = myFolders.Add(arrSubProj(I))
Next I
End If
Unfortunately, it generates a "Run-time error '5': Invalid procedure call or argument"