[英]How can I calculate a formula in Excel VBA and put its value in a variable? For example I want to set x equal to COUNTA(Sheet1!A:A)
[英]How can i create for example 5 folders out of an excel sheet with vba?
我使用以下vba代码创建一个包含excel表数据的文件夹结构:
Option Explicit
Declare Function MakePath& Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal sPath$)
Sub CreatePaths()
Dim i&
With Tabelle1
For i = 1 To .Cells(.Rows.Count, "E").End(xlUp).Row
MakePath .Cells(i, "E").Text
Next
End With
End Sub
“C:\\用户\\ XXXXX \\桌面\\测试\\ H01 \\ U01 \\ UU01”
每行都在我选择的文件夹中创建为文件夹结构,直到这里它完成我需要的操作。 E列添加了列AD并用反斜杠分隔。 现在我需要在列'E'的每个文件夹中添加例如4个文件夹(A,B,C,D),我试图添加它但它不起作用。 我必须添加到我的vba代码中以便创建文件夹?
这样的事情怎么样:
Option Explicit
Declare Function MakePath& Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal sPath$)
Sub CreatePaths()
Dim i&, subfolders As Variant, subfolder As Variant
subfolders = Split("A,B,C,D", ",")
With Tabelle1
For i = 1 To .Cells(.Rows.Count, "E").End(xlUp).Row
For Each subfolder In subfolders
MakePath .Cells(i, "E").Text & "\" & subfolder
Next
Next
End With
End Sub
尝试这个,因为你在A列中有一个根文件夹。我们将这称为我们的ParentDirectory,当我们遍历内部文件夹时,在B,C,D栏上我们将创建单个文件夹名称“A,B,C, D“分别为。
Option Explicit
Declare Function MakePath& Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal sPath$)
Sub CreatePaths()
Dim i As Integer, x As Integer
Dim currentDirectory As String, parentDirectory As String
With Tabelle1
For i = 1 To .Cells(.Rows.Count, "E").End(xlUp).Row
parentDirectory = .Cells(i, 1) & "\"
For x = 2 To 4
currentDirectory = parentDirectory & .Cells(i, x).Text & "\"
MakePath currentDirectory
MakePath currentDirectory & "A\"
MakePath currentDirectory & "B\"
MakePath currentDirectory & "C\"
MakePath currentDirectory & "D\"
parentDirectory = currentDirectory
Next x
Next
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.