我已经创建了一个脚本,它可以在整个网站和其他地方发现,用于分配作业号码。它(应该)在“Jobs”目录中搜索最高的作业号,增加1,提示输入客户名称和作业名称,复制模板目录并使用提供的信息重命名。我知道我的代码很乱,但它工作得很好......直到有人把数字放在工作名称中(09889KM-TCM-Vadata PDX50 - POD 3)。它现在完成它的预期工作,但然后再次运行它在作业名称中找到的下一个数字,即增量09889到09890然后在PDX50上拾取并尝试创建一个新文件夹00051.我一直在寻找如何找到如何我自己隔离数字,但是由于这个脚本正在制作中,我没有选择求助。请协助如何隔离前5位数字,或在一次运行后停止。
Option Explicit
Dim objFSO
Dim objNewFolder
Dim fs
Dim MainFolder
DIM JobNumber, nJobNumber, EmplInit, CustName, JobName
Dim fldr, LastName, LastJob, r, x, y
Dim OldFolder, sFile
'Find Highest Job Number Folder
Set fs = CreateObject("Scripting.FileSystemObject")
Set MainFolder = fs.GetFolder("C:\Test\")
For Each fldr In MainFolder.SubFolders
If fldr.Name > LastName Then
LastJob = fldr.Name
LastName = fldr.Name
End If
Next
'Extract JobNumber from name and increment by 1, and format to five numbers
Set r=new regexp
r.pattern="[0-9]+"
r.global=true
x=LastJob
Set y=r.execute(x)
For each JobNumber in y
JobNumber = Right("00000" & JobNumber, 5)
nJobNumber = JobNumber + 1
nJobNumber = Right("00000" & nJobNumber, 5)
' Start recieving input
' Get initials
EmplInit = InputBox ("The last Job Number is: " & VbCrLf & Jobnumber & VbCrLf & "You have been assigned Job Number: " & VbCrLf & nJobNumber & VbCrLf & "Please Typer your initials:","Initials")
If IsEmpty(EmplInit) Then
MsgBox "Canceled"
ElseIf Len(EmplInit) = 0 Then
MsgBox "You Clicked OK but left the box blank"
Else
'Get Customer Name
CustName = InputBox ("Please enter your customer's name:","Customer Name")
If IsEmpty(EmplInit) Then
MsgBox "Canceled"
ElseIf Len(EmplInit) = 0 Then
MsgBox "You Clicked OK but left the box blank"
Else
'Get Job Name
JobName = InputBox ("Please enter your job's name:","Job Name")
If IsEmpty(EmplInit) Then
MsgBox "Canceled"
ElseIf Len(EmplInit) = 0 Then
MsgBox "You Clicked OK but left the box blank"
Else
' Create New Job Folder Name
objNewFolder = ("C:\Test\" & nJobNumber & EmplInit & "-" & CustName & "-" & JobName)
'Create the File System Object
Set objFSO = CreateObject ("Scripting.FileSystemObject")
'Get the folder we want to copy from
OldFolder = "C:\Test\00AA-Working Edit - Folder Template\"
'Check if new folder exists, if not then create it.
If objFSO.FolderExists (objNewFolder) then
WScript.Echo "The Destination Folder " & objNewFolder & " already exists"
Else
WScript.Echo "The Destination Folder " & objNewFolder & " will be created."
Set objNewFolder = objFSO.CreateFolder (objNewFolder)
End If
'Copy source folders to new folder
objFSO.CopyFolder "C:\Test\00AA-Working Edit - Folder Template\*" , (objNewFolder & "\")
'Copy any files in the source root to new location
For Each sFile In objFSO.GetFolder(OldFolder).Files
If Not objFSO.FileExists(objNewFolder & "\" & objFSO.GetFileName(sFile)) Then
objFSO.GetFile(sFile).Copy objNewFolder & "\" & objFSO.GetFileName(sFile),True
End If
Next
End If
End If
End If
Next
答案 0 :(得分:0)
改变这个:
'Extract JobNumber from name and increment by 1, and format to five numbers
Set r=new regexp
r.pattern="[0-9]+"
r.global=true
x=LastJob
对此:
'Extract JobNumber from name and increment by 1, and format to five numbers
Set r=new regexp
r.pattern="[0-9]+"
r.global=true
x=Left(LastJob,5)
你只是换一行(最后一行)。
答案 1 :(得分:0)
我认为你不需要正则表达式。事实上,这听起来像是你问题的一部分,因为除了找到前5位数字之外,它还在中找到中的任何数字并对其进行操作
确定LastJob
后,请执行以下操作:
x = Left(LastJob, 5)
If IsNumeric(x) Then
nJobNumber = Right("00000" & x + 1, 5)
' Start your InputBox() prompts...
End If
答案 2 :(得分:0)
r.pattern="^[0-9]+"
为了避免代码中的更多更改,只需在正则表达式中指明模式应该位于行的开头。