Hướng dẫn tạo nút bấm tự chỉnh Vị trí – Kích thước hình QRcode trên chứng thư file word.

  1. Code Macro
Selection.ShapeRange.WrapFormat.Type = wdWrapFront
Selection.ShapeRange.Width = 45.35
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoFalse
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Rotation = 0#
Selection.ShapeRange.PictureFormat.Brightness = 0.5
Selection.ShapeRange.PictureFormat.Contrast = 0.5
Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic
Selection.ShapeRange.PictureFormat.CropLeft = 0#
Selection.ShapeRange.PictureFormat.CropRight = 0#
Selection.ShapeRange.PictureFormat.CropTop = 0#
Selection.ShapeRange.PictureFormat.CropBottom = 0#
Selection.ShapeRange.Left = 196.15
Selection.ShapeRange.Top = 429.7
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionPage
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
Selection.ShapeRange.RelativeHorizontalSize = wdRelativeHorizontalSizePage
Selection.ShapeRange.RelativeVerticalSize = wdRelativeVerticalSizePage
Selection.ShapeRange.Left = InchesToPoints(0.5)
Selection.ShapeRange.LeftRelative = wdShapePositionRelativeNone
Selection.ShapeRange.Top = InchesToPoints(10.5)
Selection.ShapeRange.TopRelative = wdShapePositionRelativeNone
Selection.ShapeRange.WidthRelative = wdShapeSizeRelativeNone
Selection.ShapeRange.HeightRelative = wdShapeSizeRelativeNone
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.LayoutInCell = True
Selection.ShapeRange.WrapFormat.AllowOverlap = True
Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
Selection.ShapeRange.WrapFormat.DistanceTop = CentimetersToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceBottom = CentimetersToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceLeft = CentimetersToPoints(0.32)
Selection.ShapeRange.WrapFormat.DistanceRight = CentimetersToPoints(0.32)
Selection.ShapeRange.WrapFormat.Type = 3
Selection.ShapeRange.ZOrder 4

2. Code Tạo PDF

On Error GoTo Errhandler

    If InStrRev(ActiveDocument.FullName, ".") <> 0 Then

        Dim strPath As String
        strPath = Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, ".") - 1) & ".pdf"

        ActiveDocument.SaveAs FileName:=strPath, FileFormat:=wdFormatPDF
    End If

    On Error GoTo 0

    Exit Sub

Errhandler:

    MsgBox "There was an error saving a copy of this document as PDF. " & _
    "Ensure that the PDF is not open for viewing and that the destination path is writable. Error code: " & Err

2. Các Bước thực hiện

2.1 Bước 1: Phần mềm Word chọn View (1)--> Macro (2) --> Record Macro (3).

2.2. Bước 2: Xuất hiện hộp thoại chọn đặt tên Macro (1) sau đó click chọn Button (2)

2.3. Bước 3: Click chọn (1) -> Click chọn Add (2) -> chọn (3) -> Chọn (4) để chỉnh icon Chọn OK để lưu lại.

2.4. Bước 4: Chọn View (1) -> Chọn Macro (2) -> chọn Stop Recording (3)

2.5. Bước 5: Chọn View Macro để chỉnh sửa code

2.6. Bước 6 : Chọn Tên QR code -> Chọn Edit

2.7. Bước 7: Chèn nội dung code phía đầu trang vào vị trí trước dòng “End Sub” lưu ý Enter xuống hàng rồi dán nội dung code vào.

2.8. Bước 8: Chỉnh sửa thông tin vị trí QR theo từng máy in để in ra vị trí chính xác tại 2 dòng
(1) : khoảng cách lề trái.
(2) : Khoảng cách lề trên.

2.9. Bước 9 – Chuột phải vào hình QR -> Chọn Wrap Text -> In Front of Text

2.10. Bước 10 – Click chọn nút Macro QR code và kiểm tra hình QR đã đúng vị trí.