Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1391|回复: 2

求助此段代码如何设置首字凹两行

[复制链接]
发表于 2013-6-24 18:03 | 显示全部楼层 |阅读模式
本帖最后由 qinhuan66 于 2013-6-25 08:30 编辑

求助此段代码如何设置凹两行(如图)谢谢
1、第一试室(共30人):凹两行;仿宋_GB2312字体16号字加粗
2、安排报考......................凹两行;仿宋_GB2312字体16号字
如何凹两行.rar (18.53 KB, 下载次数: 1)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2013-6-24 19:26 | 显示全部楼层
代码以下
Private Sub CommandButton1_Click()
    Dim objWord As Object
    Set objWord = CreateObject("word.application")
    Dim intSum As Integer
    Dim strT() As String
   
    Dim arr, i As Long, K As Long
    Dim strTemp As String
    strTemp = "试室安排考生说明" & vbCr
    arr = Range("a1").CurrentRegion
    With objWord
        .Documents.Add
        For i = LBound(arr) + 1 To UBound(arr)
            intSum = 0
            strT = Split(CStr(arr(i, 2)), "、")
            For K = LBound(strT) To UBound(strT)
                intSum = intSum + GetInt(strT(K))
            Next
            
            strTemp = strTemp & "第" & Replace(Application.WorksheetFunction.Text(arr(i, 1), "[DBNum1][$-804]General"), "一十", "十") & "试室" & "(共" & intSum & "人):" & vbCrLf & arr(i, 2) & "。" & vbCrLf '& "。"  (每句结束加句号),vbcrlf &(换行)
        Next
        .Selection.InsertAfter strTemp
        .Selection.HomeKey Unit:=wdStory
        With .ActiveDocument
            With .Sentences(1)
                .Font.Bold = True
                .Font.Size = 16
                .Font.Name = "黑体"
                .ParagraphFormat.Alignment = wdAlignParagraphCenter
                .ParagraphFormat.LineSpacing = 20
            End With
        End With

        With .Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Replacement.Font.Bold = True
            .Text = "第 [0-9]{1,} 教室"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
        End With
        
        .ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "\试室安排考生说明" & "\试室安排考生说明.doc", FileFormat:=0
        MsgBox .ActiveDocument.FullName
        .ActiveDocument.Close False
        .Quit
    End With
End Sub


Function GetInt(strV As String) As Integer
    Dim regex As Object
    Dim str As String
    Set regex = CreateObject("VBScript.RegExp")
    With regex
        .Global = True
        .Pattern = "[^\d]"
        GetInt = CInt(.Replace(strV, ""))
    End With
End Function


回复

使用道具 举报

 楼主| 发表于 2013-6-24 23:10 来自手机 | 显示全部楼层
本帖最后由 qinhuan66 于 2013-6-25 08:14 编辑

凹两个字可以了。strTemp = strTemp & "    第" & Replace(Application.WorksheetFunction.Text(arr(i, 1), "[DBNum1][$-804]General"), "一十", "十") & "试室" & "(共" & intSum & "人):" & vbCrLf & "    " & arr(i, 2) & "。" & vbCrLf  '& "。"  (每句结束加句号),vbcrlf &(换行)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-30 02:57 , Processed in 0.270506 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表