我尝试遍历表并将已知副本中的已命名文件复制到项目文件夹,以自动执行当前手动过程。我已经掌握了我想要复制的字符串以及在哪里,但我得到的对象并不支持这种方法或属性'在FileCopy本身。我所拥有的是:
Sub OEMFileCopy()
Dim str, oem, oemArray() As String
Dim folderLetter, folder, oemFolder, company, copyFrom As String
Dim oTable As Table
Dim oRow As Row
Dim myRng As Range
Dim i As Integer
Dim fso
oemFolder = "M:\Technical Support\Project Documentation\O.E.M Tech Literature"
Set fso = CreateObject("Scripting.FileSystemObject")
For Each oTable In ActiveDocument.Tables
oTable.Cell(1, 1).Select
str = Selection.Text
str = Left(str, Len(str) - 2) ' << remove end of cell characters
' Test maintenance table
If (str Like "Manufacturer") Then
For Each oRow In oTable.Rows
Set myRng = oTable.Cell(oRow.Index, 3).Range
myRng.MoveEnd wdCharacter, -1
oem = myRng.Text
Set myRng = oTable.Cell(oRow.Index, 1).Range
myRng.MoveEnd wdCharacter, -1
company = myRng.Text
Debug.Print ("Company is " & company)
If (Not ((oem Like "*O.E.M*") Or (oem Like "*OEM*") Or (oem Like "*WWW*") Or (oem Like "*www*"))) Then
oemArray() = Split(oem, ", ") '<< split into array of OEM filenames
For i = LBound(oemArray) To UBound(oemArray) '<< print each oem to output file
folderLetter = Left(oemArray(i), 1)
folder = ActiveDocument.Path & "\OEM Technical Literature\" & folderLetter & "\" & company
copyFrom = oemFolder & "\" & folderLetter & "\" & company & "\" & oemArray(i) & ".pdf"
If (fso.FolderExists(folder)) Then
folder = folder & "\"
fso.FileCopy copyFrom, folder
Else
fso.CreateFolder (folder)
End If
Next i
End If
Next oRow
End If
Next oTable
End Sub
我打印了copyFrom和文件夹并检查它们是否存在。他们看着像是: copyFrom - M:\技术支持\项目文档\ O.E.M技术文献\ A \ ABB \ A1285.pdf 文件夹 - 文件夹M:\技术支持\项目文档\ 2。正在进行的工作\当前项目\ TEST \ 2。手册草案\ OEM技术文献\ A \ ABB \
文件在复制目的地中不存在,文件夹确实存在。
任何帮助将不胜感激。谢谢。
答案 0 :(得分:2)
您混淆了文件复制命令:
CopyFile
是基础VBA语言中可用的命令之一。
FileSystemObject
是fso.FileCopy copyFrom, folder
对象可用的方法之一。
所以,而不是使用
fso.CopyFile copyFrom, folder
使用
from amazon.api import AmazonAPI
amazon = AmazonAPI(aws_key='XXX', aws_secret='XXX', aws_associate_tag='XXX', region="DE")
product = amazon.lookup(ItemId='B003P0ZB1K')
print(product.large_image_url)
代替。