病程续打程序(word vba)

因为工作需要,自己写的用于医疗病历的病历续打程序,无模板限制,在word中使用,也可用于任意文件的定位续打

--------------------------------------------

 

Sub 病程续打()
'
' 病程续打 3.1版本

'版本信息
'3.1版 完全实现与模板无关打印,自动调用当前文件设置
'3.0版 实现多模板续打
'2.1版 增加提示信息,防止误续打
'2.0版 实现多页续打
'1.0版 实现单页续打
 
 
 
 
 
' 条件判断
'------------------------------------------
 
    Dim dl As Range, yema As Byte
    Set dl = Selection.Range
    yema = Selection.Information(wdActiveEndPageNumber)
    
    Dim boxsbj As Long, boxzbj As Long, boxkd As Long
    boxsbj = Selection.Information(wdVerticalPositionRelativeToPage)
    boxzbj = Selection.Information(wdHorizontalPositionRelativeToPage)
        
    Dim ymzbj As Long, ymybj As Long, ymsbj As Long, ymxbj As Long
    Dim ymym As Long, ymyj As Long, ymkd As Long, ymgd As Long, ymhwg As Long
    ymsbj = ActiveDocument.PageSetup.TopMargin
    ymxbj = ActiveDocument.PageSetup.BottomMargin
    ymzbj = ActiveDocument.PageSetup.LeftMargin
    ymybj = ActiveDocument.PageSetup.RightMargin
    ymym = ActiveDocument.PageSetup.HeaderDistance
    ymyj = ActiveDocument.PageSetup.FooterDistance
    ymkd = ActiveDocument.PageSetup.PageWidth
    ymgd = ActiveDocument.PageSetup.PageHeight
    ymhwg = ActiveDocument.PageSetup.LinesPage
    
        
    If Selection.Paragraphs.Count < 3 Then
   dlxz = MsgBox("未完整选择病程记录,如果确需打印请选择是", vbYesNo)
    If dlxz = vbNo Then
   Exit Sub
   End If
   End If
   
   Selection.Copy
 
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    If Selection.Information(wdActiveEndPageNumber) <> yema Then
    MsgBox "选择内容不在同一页上,请重新选择"
    Exit Sub
    End If
 
 
 
   If Selection.Information(wdFirstCharacterLineNumber) = 1 Then
    shxz = MsgBox("所选内容是本页第一部分,将直接打印当前页.", vbYesNo)
    If shxz = vbNo Then
    Exit Sub
    Else
       Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
        False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
    Exit Sub
    End If
   End If
   
'新建文档
'---------------------------------
     Documents.add DocumentType:=wdNewBlankDocument
    
'页面设置
'--------------------
    With ActiveDocument.PageSetup
        .TopMargin = ymsbj
        .BottomMargin = ymxbj
        .LeftMargin = ymzbj
        .RightMargin = ymybj
        .HeaderDistance = ymym
        .FooterDistance = ymyj
        .PageWidth = ymkd
        .PageHeight = ymgd
        .LinesPage = ymhwg
        .LayoutMode = wdLayoutModeLineGrid
    End With
    
'插入文本框
'------------
    boxkd = ActiveDocument.PageSetup.PageWidth - ActiveDocument.PageSetup.LeftMargin - ActiveDocument.PageSetup.RightMargin
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, boxzbj, boxsbj, boxkd, 124.65).Select
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.TextFrame.MarginLeft = 0
    Selection.ShapeRange.TextFrame.MarginRight = 0
    Selection.ShapeRange.TextFrame.MarginTop = 0
    Selection.ShapeRange.TextFrame.MarginBottom = 0
    Selection.ShapeRange.Left = wdShapeLeft
 
 
'粘贴
'----------
    Selection.ShapeRange.TextFrame.TextRange.Select
    Selection.Collapse
    Selection.Paste
    
'自动调整文本框高度
'------------------
    Selection.ShapeRange.TextFrame.AutoSize = True
    
 '打印当前页
 '--------------
    Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
        False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
 '关闭临时文档
 '-------------
    ActiveDocument.Close (wdDoNotSaveChanges)
    
    
End Sub
 
' 病程续打 3.1版本

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值