回答
我不知道你问什么,但也许正是这种...
Sub GetFolder_Data_Collection()
Range("A:L").ClearContents
Range("A1").Value = "Name"
Range("B1").Value = "Path"
Range("C1").Value = "Size (KB)"
Range("D1").Value = "DateLastModified"
Range("E1").Value = "Attributes"
Range("F1").Value = "DateCreated"
Range("G1").Value = "DateLastAccessed"
Range("H1").Value = "Drive"
Range("I1").Value = "ParentFolder"
Range("J1").Value = "ShortName"
Range("K1").Value = "ShortPath"
Range("L1").Value = "Type"
Range("A1").Select
Dim strPath As String
'strPath = "I:\Information Security\KRI Monthly Data Collection\"
strPath = GetFolder
Dim OBJ As Object, Folder As Object, File As Object
Set OBJ = CreateObject("Scripting.FileSystemObject")
Set Folder = OBJ.GetFolder(strPath)
Call ListFiles(Folder)
Dim SubFolder As Object
For Each SubFolder In Folder.SubFolders
Call ListFiles(SubFolder)
Call GetSubFolders(SubFolder)
Next SubFolder
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ListFiles(ByRef Folder As Object)
On Error Resume Next
For Each File In Folder.Files
ActiveCell.Offset(1, 0).Select
ActiveCell = File.Name
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(0, 1) = File.Path
ActiveCell.Offset(0, 0).Hyperlinks.Add Anchor:=ActiveCell.Offset(0, 0), Address:=File.Path, TextToDisplay:=File.Path
ActiveCell.Offset(0, -1).Select
ActiveCell.Offset(0, 2) = (File.Size/1024) 'IN KB
ActiveCell.Offset(0, 3) = File.DateLastModified
ActiveCell.Offset(0, 4) = File.Attributes
ActiveCell.Offset(0, 5) = File.DateCreated
ActiveCell.Offset(0, 6) = File.DateLastAccessed
ActiveCell.Offset(0, 7) = File.Drive
ActiveCell.Offset(0, 8) = File.ParentFolder
ActiveCell.Offset(0, 9) = File.ShortName
ActiveCell.Offset(0, 10) = File.ShortPath
ActiveCell.Offset(0, 11) = File.Type
Next File
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GetSubFolders(ByRef SubFolder As Object)
Dim FolderItem As Object
On Error Resume Next
For Each FolderItem In SubFolder.SubFolders
Call ListFiles(FolderItem)
Call GetSubFolders(FolderItem)
Next FolderItem
End Sub
Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function
这是一个完全不同的事情。如果你想通过电子邮件发送不同的文件对不同的人,建立一个Excel“模板”根据您的具体需求,并运行下面的脚本。
请在表( “工作表Sheet1”)的列表:人民 在B列的名称:在A列
E-mail地址 在列C:Z:文件名类似这样的C:\ Data \ Book2.xls(不一定是Excel文件)
宏将循环遍历“Sheet1”中的每一行,并且如果B列中存在电子邮件地址 和文件名列C:Z它会创建一封包含此信息的邮件并发送。
Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
.Send 'Or use .Display
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
抱歉误会。 – TudyBTH
我会更详细地描述的情况。 (对不起我的英语,我在英语课上踢足球。)我有一个模板,我已经编写了为每个人生成文件的代码。我将这些文件保存在OnDrive(本地同步文件夹)中。 **现在我想编写一个从OneDrive中提取共享链接的代码(VBA-Excel),以便为每个生成的文件进行编辑。**我希望在OneDrive中进行身份验证的示例代码并调用OneDrve API以返回一个共享 - 链接进行编辑,为该文件夹中的每个文件。这是我的问题。 – TudyBTH
那么,有人可以给我一个使用VBA调用OneDrive API的例子吗?请!!! – TudyBTH
如果你想不同的文件通过电子邮件发送给不同的人,看到下面的脚本。
请在表( “工作表Sheet1”)的列表:
在列A:E-mail地址
在列C:Z中的人
在B列的名称:喜欢这款C文件名:\ DATA \ Book2.xls中(不必是Excel文件)
通过“Sheet1中”每行宏将循环,如果在B列的E-mail地址 和列C中的文件名:Z它将创建一个包含此信息的邮件并发送它。
Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
.Send 'Or use .Display
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
- 1. 获取OneDrive文件ID
- 2. 无法获取onedrive访问令牌
- 3. 使用OneDrive API获取访问令牌
- 4. 获取OneDrive文件夹层次
- 5. OneDrive SDK取消操作
- 6. 如何从onedrive API获取用户的电子邮件?
- 7. 如何在OneDrive中获取文件的文件属性?
- 8. Onedrive VBA获取文件的共享链接
- 9. OneDrive API帮助获取文件的下载链接
- 10. 获取当前Word文档的OneDrive项目ID文档
- 11. onedrive和onedrive for business之间的配额
- 12. OneDrive选取器 - 广泛的权限
- 13. Android上的OneDrive
- 14. OneDrive粒度GPO控制(获取文件等)&域行为
- 15. 从OneDrive获取资源时需要总数
- 16. OneDrive REST API获取没有文件夹ID
- 17. OneDrive oAuth令牌请求获取CORS错误
- 18. OneDrive身份验证后获取用户详细信息
- 19. 如何通过API获取/添加OneDrive照片标签?
- 20. 在OneDrive
- 21. 如何获得ios OneDrive框架
- 22. OneDrive Webservice - 不同的用户可以访问我的OneDrive吗?
- 23. OneDrive UNC路径
- 24. OneDrive for Business quickXorHash
- 25. OneDrive SDK - Visual Basic
- 26. OneDrive API节流
- 27. InvalidRequest在onedrive
- 28. onedrive for business webhooks
- 29. 迁移到Onedrive
- 30. OneDrive REST API sortby
嗨,ryguy72,并感谢您的快速响应。我在OneDrive文件夹中有多个文件(300+)(.xlsx)。我想获得一个分享链接,以便为每个文件进行编辑。每个链接将被邮寄到一个特定的人(不同的文件 - 不同的人),这样他就可以打开和编辑一个与ExcelOnline。我认为**我需要一个使用OneDrve API和VBA **的模型。 – TudyBTH