else turn word

Sub mynewdoc()
Dim myapp As Word.Application
Set myapp = CreateObject("word.application")
Dim Row As Integer
Dim i As Integer
Dim temptexr As Single
Application.ScreenUpdating = False
Row = ActiveSheet.Range("A1").CurrentRegion.Rows.Count
myapp.Documents.Add
Dim mydoc As Document
Set mydoc = myapp.ActiveDocument
Dim mysel As Selection
Set mysel = myapp.Selection
mysel.Paragraphs.TabStops.Add Position:=InchesToPoints(1)
mysel.Paragraphs.TabStops.Add Position:=InchesToPoints(2.8)
mysel.Paragraphs.TabStops.Add Position:=InchesToPoints(3.8)
mysel.Paragraphs.TabStops.Add Position:=InchesToPoints(4.8)
mysel.InsertAfter Text:=ActiveSheet.Range("A1") & vbCrLf
With mydoc.Paragraphs(1).Range
.ParagraphFormat.Alignment = wdalignparagraphcenter
.Font.Size = 18
.Font.NameFarEast = "华文行楷"
End With
For i = 2 To Row
temptext = ActiveSheet.Cells(i, 1)
temptext = temptext & vbTab & ActiveSheet.Cells(i, 2)
temptext = temptext & vbTab & ActiveSheet.Cells(i, 4)
temptext = temptext & vbTab & ActiveSheet.Cells(i, 5)
temptext = temptext & vbTab & ActiveSheet.Cells(i, 10) & vbCrLf
myapp.Selection.InsertAfter Text:=temptext
If i = 2 Then
mydoc.Paragraphs(2).Range.Font.Bold = True
End If
Next i
mydoc.saveas2 Filename:= "D: \ My Documents .docx"
mydoc.Close
myapp.Quit
Application.ScreenUpdating = True
End Sub

Guess you like

Origin www.cnblogs.com/40630762-/p/12118086.html