Home > Software engineering >  Similar to the mail merge function
Similar to the mail merge function

Time:09-16

Can EXCEL realize the mail merge function similar to a WORD? Is made from an EXCEL spreadsheet template, and the other an EXCEL spreadsheet data source,
According to the data source automatically fill in N EXCEL spreadsheets,

Extracted from information list each record information (name, gender, birth date, join into the class and the monthly pension, the adjustment, adjusted pensions) on the corresponding position of the stamp, and automatically generate named after the name of the individual form

CodePudding user response:

 Sub X () 
Dim dataBook As Workbook
Dim dataSheet As Worksheet
Dim personBook As Workbook
Dim personSheet As Worksheet
Dim r As Long
Dim strName As String

The Set dataBook=Workbooks. Open (" data source. XLS ")
The Set dataSheet=dataBook. Sheets (1)

For r=2 To dataSheet. UsedRange. Rows. Count
StrName=dataSheet. Cells (r, 1). The Value

The Set personBook=Workbooks. The Add (" template. XLT ")
The Set personSheet=personBook. Sheets (1)
'fill the dataSheet first r row personSheet position for'

PersonBook. SaveAs strName & amp; ". XLS "

The Set personSheet=Nothing
PersonBook. Close
The Set personBook=Nothing
Next

The Set dataSheet=Nothing
DataBook. Close
The Set dataBook=Nothing
End Sub

Is probably like this above, their combined with complete directory, their perfect annotation part,

CodePudding user response:

reference 1st floor Tiger_Zhao response:
 Sub X () 
Dim dataBook As Workbook
Dim dataSheet As Worksheet
Dim personBook As Workbook
Dim personSheet As Worksheet
Dim r As Long
Dim strName As String

The Set dataBook=Workbooks. Open (" data source. XLS ")
The Set dataSheet=dataBook. Sheets (1)

For r=2 To dataSheet. UsedRange. Rows. Count
StrName=dataSheet. Cells (r, 1). The Value

The Set personBook=Workbooks. The Add (" template. XLT ")
The Set personSheet=personBook. Sheets (1)
'fill the dataSheet first r row personSheet position for'

PersonBook. SaveAs strName & amp; ". XLS "

The Set personSheet=Nothing
PersonBook. Close
The Set personBook=Nothing
Next

The Set dataSheet=Nothing
DataBook. Close
The Set dataBook=Nothing
End Sub

Is probably like this above, their combined with complete directory, their perfect annotation part,








Can you tell the contact way? Such as QQ, I didn't contact with macro, some look not to understand

CodePudding user response:

Yourself by recording a macro, Alt + F11 open the macro editor, paste the code above the same module, see a help you have not understand the statement of F1,

CodePudding user response:

To learn the essence, ah
  •  Tags:  
  • VBA
  • Related