1

我有很多 PDF 文件,我试图根据 Excel 电子表格中的标准重命名。电子表格列出了 ID、姓氏、名字。

| 123456 | Smith | Joe |

我可以很好地打开和读取 excel,可以创建 ado 连接并获得对我的查询的响应,但找不到一种方法来获取包含文件名的记录集的一部分并保存为变量。

我正在使用的代码:(更新到当前代码集)

'On Error Resume Next

LetterDirectory = InputBox("What letter are we scanning?")

DirectoryLocation = "C:\CLNotes\"
LetterDirectory = UCase(LetterDirectory)
SubDirectory = DirectoryLocation & LetterDirectory
FullDirectory = DirectoryLocation & LetterDirectory & "\*.pdf"

'Creating Excel objects
Set xl = CreateObject("Excel.Application")
Set xlBook = xl.Workbooks.Open("c:\CLnotes\dbo_Patient.xlsx")
Set xlSheet = xlBook.Worksheets(LetterDirectory)
xl.Visible = True

'Set Variables
xlRow = 1
totalRows = xl.WorksheetFunction.CountA(xlSheet.Range("A:A"))
oldFilename = 0

For xlRow = 1 to totalRows

LastName = xlSheet.Cells.Item(xlRow, 2).text
FirstName = xlSheet.Cells.Item(xlRow, 3).text
FullName = LastName & " " & Firstname
newFilename = xlSheet.Cells.Item(xlRow, 1).Text
'FullName = "b lorraine"

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open ("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';")
objRecordSet.Open ("SELECT System.FileName FROM SYSTEMINDEX WHERE Contains('" & FullName & "')"), objConnection
objRecordSet.MoveFirst
oldFilename = objRecordset.Fields.Item("System.FileName")
Do Until objRecordset.EOF
    Wscript.Echo objRecordset.Fields.Item("System.FileName")
    objRecordset.MoveNext
Loop
Next

谢谢。

4

1 回答 1

1

IF

Wscript.Echo objRecordset.Fields.Item("System.FileName")

outputs 'the part of the recordset that contains the filename' (you are interested in) AND

Set oldFilename = objRecordset.Fields.Item("System.FileName")

was your attempt to 'save [that value] as a variable' THEN

oldFilename = objRecordset.Fields.Item("System.FileName")

will solve your problem, because Set is to be used for assignment of objects only (not 'plain' data types like strings).

That Set var = non-object is the cause of your trouble - as I assume - is hidden by your use of the EVIL global On Error Resume Next.

于 2013-03-19T21:36:33.143 回答