回答
我不知道你問什麼,但也許正是這種...
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