Home > Software engineering >  Using vb language to convert the excel spreadsheet to TXT file
Using vb language to convert the excel spreadsheet to TXT file

Time:09-27

Vb macros to excel at random into n folders, each folder has 10 TXT file, can you do?


Here are all the excel conversion in a folder, for example,
 Dim intLastRow, arr, intLoop 

IntLastRow=Cells (Rows) Count, 1.) the End (xlUp). Row
Arr=Range (" a1: b "& amp; IntLastRow)
For intLoop=1 To UBound (arr)
Open "D: \ ceshi " & amp; Arr (intLoop, 1) & amp; ". TXT "For the Output As the # 1
Print # 1, arr (intLoop, 1)
Close # 1
Next

CodePudding user response:

This macro command can't meet my requirements, for a great god help below the answer

CodePudding user response:

Can be the reference for example, I help change, is classified into multiple folders!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1

CodePudding user response:

 Option Explicit 

The Function RandFolder (ByVal Count As Long) As a String ()
Dim (a) As String
Dim As Long I
Dim j As Long
Dim t As String

'build directory'
ReDim a (Count - 1)
For I=0 To Count - 1
A (I)="D: \ ceshi " & amp; I & amp; ""
If LenB (Dir (a (I), vbDirectory))=0 Then
The MkDir a (I)
End the If
Next

'shuffle'
Randomize
For I=0 To Count - 1
J=Int (Rnd () * Count)

T=a (I)
A (I)=a (j)
A (j)=t
Next

RandFolder=a
End the Function

Dim intLastRow, arr, intLoop
Dim lFolderCount As Long
Dim aFolders () As String

IntLastRow=Cells (Rows) Count, 1.) the End (xlUp). Row
Arr=Range (" a1: b "& amp; IntLastRow)

LFolderCount=(UBound (arr) - 1) 10
\AFolders=RandFolder (lFolderCount)

For intLoop=1 To UBound (arr)
'every 10 files to a directory'
The Open aFolders ((intLoop - 1) \ 10) & amp; Arr (intLoop, 1) & amp; ". TXT "For the Output As the # 1
Print # 1, arr (intLoop, 1)
Close # 1
Next
  •  Tags:  
  • VBA
  • Related