|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
* 前两天,单位有人让制作几个标签,结果,用通用模板中的“标签”宏制作后,出入很大,不实用,所以这两天考虑重新制作这个宏,其实,这个宏多数是录制宏的结合,编的很少,但感觉很实用了,起码本单位以后再用就方便多了。
* 请注意:请把要制作标签的文字放在一个表格中,且该表格要仅有一列!这样让《标签宏》处理它,纵向/横向就都好办了。
* 应用此宏后,纵向标签可以设置字符缩放为120%或150%让字体变得修长些;横向标签可以设置为90%让字体变得修长些;同时,字体没有变化,请自行选用中文字体。
* 此宏其实还可以再精简些,但为了保持完整性,并继续观察是否好用(如果某条语句出错,请在宏前面加上 on error resume next)。——比原来的此宏减少一半代码。- Sub 标签()
- If Selection.Information(wdWithInTable) = False Then MsgBox "请将光标放在标签数据源表格中!", vbOKOnly + vbCritical, "标签": End
- If Selection.Tables(1).Columns.Count <> 1 Then MsgBox "标签数据源表格仅允许有一列!", vbOKOnly + vbCritical, "标签": End
- Dim i As String
- i = MsgBox("是:纵向标签(书脊) 否:横向标签(封面) 取消:放弃", vbYesNoCancel + vbExclamation, "标签")
- If i = vbCancel Then End
- Selection.Tables(1).Range.Copy
- Documents.Add.Content.Paste
- Selection.Tables(1).Select
- Selection.Font.Bold = True
- Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
- Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
- With ActiveDocument.PageSetup
- .TopMargin = CentimetersToPoints(2)
- .BottomMargin = CentimetersToPoints(2)
- .LeftMargin = CentimetersToPoints(1)
- .RightMargin = CentimetersToPoints(1)
- End With
- If i = vbYes Then '纵向标签
- ActiveDocument.PageSetup.Orientation = wdOrientLandscape
- Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
- Selection.Rows.HeightRule = wdRowHeightExactly
- Selection.Rows.Height = CentimetersToPoints(3)
- Selection.Orientation = wdTextOrientationHorizontalRotatedFarEast
- Selection.ParagraphFormat.Alignment = wdAlignParagraphDistribute
- Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
- Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
- Selection.Font.Size = 48
- ElseIf i = vbNo Then '横向标签
- Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
- Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
- ActiveDocument.Range(Start:=Selection.End, End:=Selection.End).InsertBreak Type:=wdSectionBreakContinuous
- With Selection.PageSetup.TextColumns
- .SetCount NumColumns:=2
- .EvenlySpaced = True
- .LineBetween = False
- .Width = CentimetersToPoints(8.76)
- .Spacing = CentimetersToPoints(1.48)
- End With
- Selection.Rows.HeightRule = wdRowHeightExactly
- Selection.Rows.Height = CentimetersToPoints(5)
- Selection.Font.Size = 60
- End If
- ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
- ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitFullPage
- End Sub
复制代码 标签宏数据源--示例文件 下载:
标签数据源(示例).rar
(3.73 KB, 下载次数: 304)
|
|