Home > Software engineering >  Pray god help me write the vb code
Pray god help me write the vb code

Time:11-12

Write a code for great god help me help specific requirements are as follows:
In a folder there are a number of TXT and excel spreadsheets as shown in figure 1
Make a list of the I figure 3 excel wage into numerical
In figure 2 TXT corresponding personnel in the final 0.00 the column (the id number in the TXT and excel is not only repeat)

CodePudding user response:

Write well, code is as follows:
 
The Set dict=createobject (" scripting. The dictionary ")
The Set of fso=createobject (" scripting. Filesystemobject ")
Curdir=fso. Getparentfoldername (wscript. Scriptfullname)
The Set objfolder=fso. Getfolder (curdir)
The Set reg=createobject (" vbscript. Regexp ")
Reg. Global=True
Reg. Multiline=True
Reg. The ignorecase=True
Reg. The pattern="^ \ \ S * (t) (\ S *) (\ t \ \ t \ S \ S * * t t \ S \ \ S * *? \ \ S * * t). * $"

The Set of excel=createobject (" excel. Application ")
Excel. Visible=True

For Each objfile In objfolder. Files
If StrComp (fso) getextensionname (objfile. Name), "XLSX", 1)=0 Then
Set wb.=excel workbooks. Open (objfile. Path)
I=4

Set the ws=wb. Sheets (1)
While the ws. Cells (I, "F") & lt;> "
"Dict. Add CStr (ws) cells (I, "F")), CStr (ws) cells (I, "I"))
I=I + 1
Wend

Wb. Close
End the If
Next

Excel. Quit

For Each objfile In objfolder. Files
If StrComp (fso) getextensionname (objfile. Name), "TXT", 1)=0 Then
Set the stream=fso. Opentextfile (objfile. Path, 1, False)
The content=stream. Readall
Stream. Close

Set the stream=fso. Opentextfile (objfile. Path, 2, True)

The Set colmatches=reg. The execute (content)
For Each objmatch colmatches In
If dict. The exists (objmatch submatches (1)) Then
Stream. Writeline objmatch. Submatches (0) & amp; Objmatch. Submatches (1) & amp; Objmatch. Submatches (2) & amp; FormatNumber (dict (objmatch submatches (1)), 2, 2, 2, 0)
The Else
Stream. Write objmatch. Value
End the If
Next

Stream. Close
End the If
Next

Msgbox "done!"

Download address:
Link: https://pan.baidu.com/s/1xmKHrlnn8Z1mLkhafw5c5w
The extracted code: jl2z

CodePudding user response:

reference 1st floor milaoshu1020 response:
write well, the code is as follows:
 
The Set dict=createobject (" scripting. The dictionary ")
The Set of fso=createobject (" scripting. Filesystemobject ")
Curdir=fso. Getparentfoldername (wscript. Scriptfullname)
The Set objfolder=fso. Getfolder (curdir)
The Set reg=createobject (" vbscript. Regexp ")
Reg. Global=True
Reg. Multiline=True
Reg. The ignorecase=True
Reg. The pattern="^ \ \ S * (t) (\ S *) (\ t \ \ t \ S \ S * * t t \ S \ \ S * *? \ \ S * * t). * $"

The Set of excel=createobject (" excel. Application ")
Excel. Visible=True

For Each objfile In objfolder. Files
If StrComp (fso) getextensionname (objfile. Name), "XLSX", 1)=0 Then
Set wb.=excel workbooks. Open (objfile. Path)
I=4

Set the ws=wb. Sheets (1)
While the ws. Cells (I, "F") & lt;> "
"Dict. Add CStr (ws) cells (I, "F")), CStr (ws) cells (I, "I"))
I=I + 1
Wend

Wb. Close
End the If
Next

Excel. Quit

For Each objfile In objfolder. Files
If StrComp (fso) getextensionname (objfile. Name), "TXT", 1)=0 Then
Set the stream=fso. Opentextfile (objfile. Path, 1, False)
The content=stream. Readall
Stream. Close

Set the stream=fso. Opentextfile (objfile. Path, 2, True)

The Set colmatches=reg. The execute (content)
For Each objmatch colmatches In
If dict. The exists (objmatch submatches (1)) Then
Stream. Writeline objmatch. Submatches (0) & amp; Objmatch. Submatches (1) & amp; Objmatch. Submatches (2) & amp; FormatNumber (dict (objmatch submatches (1)), 2, 2, 2, 0)
The Else
Stream. Write objmatch. Value
End the If
Next

Stream. Close
End the If
Next

Msgbox "done!"

Download address:
Link: https://pan.baidu.com/s/1xmKHrlnn8Z1mLkhafw5c5w
Extract the code: jl2z

The only support XLSX format, XLS format is not supported

CodePudding user response:

refer to the second floor weixin_41496887 response:
the only support XLSX format, does not support XLS format

Revised:
 
The Set dict=createobject (" scripting. The dictionary ")
The Set of fso=createobject (" scripting. Filesystemobject ")
Curdir=fso. Getparentfoldername (wscript. Scriptfullname)
The Set objfolder=fso. Getfolder (curdir)
The Set reg=createobject (" vbscript. Regexp ")
Reg. Global=True
Reg. Multiline=True
Reg. The ignorecase=True
Reg. The pattern="^ \ \ S * (t) (\ S *) (\ t \ \ t \ S \ S * * t t \ S \ \ S * *? \ \ S * * t). * $"

The Set of excel=createobject (" excel. Application ")
Excel. Visible=True

For Each objfile In objfolder. Files
If StrComp (Left (fso) getextensionname (objfile. Name), 3), "like", 1)=0 Then
Set wb.=excel workbooks. Open (objfile. Path)
I=4

Set the ws=wb. Sheets (1)
While the ws. Cells (I, "F") & lt;> "
"nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related